0
我想在登錄Activity
上創建一個Toast
文本(關於我沒有在數據庫中註冊)。但是,當我放入Toast
文本時出現問題。如果我把它放在一個while循環中,它會循環儘可能多的條目。使用Content Provider的登錄詳細信息,帶來很多循環
環
if(cursor!=null)
{
{
int i = 0;
while(cursor.moveToNext())
{
if(cursor.getString(i).equals(input_email) && cursor.getString(i).equals(input_password))
{
Log.d(TAG, "Udah masuk belum ");
Toast.makeText(getApplicationContext(),"Login Successful!", Toast.LENGTH_SHORT).show();
Intent intent =new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
finish();
i = i + 1;
}
else
{
Toast.makeText(getApplicationContext(),"You haven't Registered yet!", Toast.LENGTH_SHORT).show();
Intent intent =new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
finish();
}
}
cursor.close();
}
}
內,但如果我的推杆循環外,它所帶來的誤差。你知道這個解決方案是什麼嗎?
環
String [] projection ={ServiceProvidersContract.Columns.SEmail, ServiceProvidersContract.Columns.spPassword};
Cursor cursor = contentResolver.query(ServiceProvidersContract.CONTENT_URI, projection, null, null, null);
Log.d(TAG, "Checking Cursor" + cursor);
if(cursor!=null)
{
{
int i = 0;
while(cursor.moveToNext())
{
if(cursor.getString(i).equals(input_email) && cursor.getString(i).equals(input_password))
{
Log.d(TAG, "Udah masuk belum ");
Toast.makeText(getApplicationContext(),"Login Successful!", Toast.LENGTH_SHORT).show();
Intent intent =new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
finish();
i = i + 1;
}
}
cursor.close();
if(!cursor.getString(i).equals(input_email) && cursor.getString(i).equals(input_password))
{
Toast.makeText(getApplicationContext(),"You haven't Registered yet!", Toast.LENGTH_SHORT).show();
Intent intent =new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
finish();
}
}
}
你得到什麼錯誤? –
正如你迭代while循環你cusror有說100個值,所以如果它不進入所有的價值,如果條件else將被執行,所以100次烤麪包將被生成。 – Mrinmoy
是的,我很抱歉。我沒有把For循環放在這裏,所以這就是爲什麼它不能工作。 –