我是Android的新手,我正在編寫一個程序,當用戶單擊一個按鈕時出現一個Alert Dialog
。此警報對話框有2個按鈕,Yes and No
。點擊是/否,我需要sysout
的迴應。初學者按鈕點擊事件
我到目前爲止的代碼;有人可以幫我添加警報對話框嗎?
public class HelloWorldProjectActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myFirstScreen);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId()==(R.id.button1)){
System.out.println("first button clicked");
// I need a Alert Dialog to appear here, and that will have 2 buttons YES and NO, the users response should be printed to the console.
}
}
我應該在哪裏輸入上面的代碼?在if條件內? – Illep
請參閱我編輯的答案。 – wannik