我正在设计一个登录屏幕,并希望在单击登录按钮时显示一个带有“请稍候...”文本的旋转轮。如果用户名和密码匹配,则应显示下一个屏幕,否则应显示错误消息。我的问题是,当按下按钮时,进程对话框即将到来,但下一个屏幕或关闭对话框后不显示错误消息。我有以下代码。请帮助我在哪里做错了。
package com.example.first_db_app;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class TestDbActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_db);
DatabaseHandler db=new DatabaseHandler(this);
//CRUD operations
//inserting the records
/*Log.d("Insert: ", "Inserting ..");
db.addUser(new User("Ashwin","11111"));
db.addUser(new User("Ravi","22222"));
db.addUser(new User("Gopal","33333"));
db.addUser(new User("Satish","44444"));*/
// Reading all contacts
Log.d("Reading: ", "Reading all contacts..");
List<User> user = db.getAllContacts();
for (User us : user) {
String log = "Name: " + us.getUname() + " ,Password " + us.getUpwd();
// Writing Contacts to log
Log.d("Name: ", log);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test_db, menu);
return true;
}
public void login(View v)
{
final EditText edtuname=(EditText) findViewById(R.id.editTextUserNameToLogin);
final EditText edtpwd=(EditText) findViewById(R.id.editTextPasswordToLogin);
Button btnlogin=(Button) findViewById(R.id.buttonSignIn);
final DatabaseHandler db=new DatabaseHandler(this);
btnlogin.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
final ProgressDialog mypd=ProgressDialog.show(TestDbActivity.this, "", "Loading..",true);
new Thread (new Runnable()
{
@Override
public void run()
{
try
{
String uname= edtuname.getText().toString();
String pwd=edtpwd.getText().toString();
String stored_pwd=db.getUser(uname);
Thread.sleep(5000);
if(pwd.equals(stored_pwd))
{
//Toast.makeText(TestDbActivity.this,"successful", Toast.LENGTH_LONG).show();
mypd.dismiss();
setContentView(R.layout.activity_next);
}
else
{
mypd.dismiss();
Toast.makeText(TestDbActivity.this, "failed", Toast.LENGTH_LONG).show();
}
}
catch (Exception e)
{
}
}
}).start();
}
} );
}
}
Thanks in advance.