0
ProgressDialog的onClick不工作..這是我的代碼..基本上我想顯示加載對話框,當用戶提交登錄表單,並等待響應ProgressDialog的onClick不工作
public class LoginLayout extends MenuActivity {
ProgressDialog progress;
EditText un,pw;
TextView error;
Button ok;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
un=(EditText)findViewById(R.id.et_un);
pw=(EditText)findViewById(R.id.et_pw);
ok=(Button)findViewById(R.id.btn_login);
error=(TextView)findViewById(R.id.tv_error);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progress = ProgressDialog.show(LoginLayout.this, "Login","please...wait",true);
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://www.mysite.com/api/login.php", postParameters);
String res=response.toString();
res= res.replaceAll("\\s+","");
progress.dismiss();
if(res.equals("1"))
error.setText("Correct Username or Password");
else
error.setText("Sorry!! Incorrect Username or Password");
} catch (Exception e) {
un.setText(e.toString());
}
}
});
}
}
progress.show( ); after progress = ProgressDialog.show(LoginLayout.this,「Login」,「please ... wait」,true); 。你應該使用這個線程http://stackoverflow.com/questions/8149349/progress-dialog-on-button-click-in-android/8149536#8149536 – Sameer 2012-03-30 07:59:45