當按鈕被按下時,我試圖使對話框關閉。但每當我按下按鈕時,應用程序崩潰。對話框上的Android應用程序崩潰按鈕單擊
public class CanvasPaint extends Activity implements OnClickListener {
final Button widthbtn = (Button) findViewById(R.id.widthbtn);
final Button widthpopBtn = (Button) findViewById(R.id.widthpopBtn);
final Context context = this;
final Dialog widthDialog = new Dialog(context);
widthbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
widthpopBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
widthDialog.dismiss();
}
});
widthDialog.show();
}
});
}
請檢查您的logcat的,看看你的堆棧跟蹤:https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-解決 - 這 – CommonsWare 2014-10-26 22:04:11
一個upvote?真? – Simon 2014-10-26 23:00:56
@jyoon第二個onclick用於對話框中的按鈕 – user2552211 2014-10-26 23:04:39