美好的一天。我遇到問題,單擊按鈕時顯示一個消息框。簡單的消息框顯示註冊確認。之後,我打開新的活動。 問題是,它顯示消息框,然後啓動新的活動,而不用等待ok按鈕被點擊。如何在點擊確定按鈕後只顯示新的活動。如何在開始新活動之前等待好的按鈕
下面是我使用的代碼。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
Button btn = (Button)findViewById(R.id.registerButton);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), BookingActivity.class);
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(context);
dlgAlert.setMessage("You have successfully Registered.Please Press okay to continue");
dlgAlert.setTitle("Registration");
dlgAlert.setPositiveButton("OK", null);
dlgAlert.setCancelable(false);
dlgAlert.create().show();
startActivity(intent);
finish();
}
});
改變了代碼,以
@Override
public void onClick(View view) {
// Intent intent = new Intent(getApplicationContext(), BookingActivity.class);
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(context);
dlgAlert.setMessage("You have successfully Registered.Please Press okay to continue");
dlgAlert.setTitle("Registration");
dlgAlert.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(getApplicationContext(), BookingActivity.class);
startActivity(intent);
}
});
dlgAlert.setCancelable(false);
dlgAlert.show();
添加'listener'爲'OK'點擊裏面那個你想要做什麼。 – Rustam 2014-09-20 10:42:01