AlertDialog 생성에 문제가 있습니다.AlertDialog 문제
하나의 버튼을 클릭하면 AlertDialog가 나타나기 때문에 버튼 리스너에 대화 상자를 만들기위한 모든 코드를 넣으십시오 ... 동일한 코드가 리스너 외부에서 작동하지만 리스너가 작동하지 않습니다 ... it
이가 내 코드입니다 .... "Aplication가 예기치 않게 종료되었습니다": 오류를 호출하지만 난 시작할 때 작성 에뮬레이터는 이것에 대해 뭔가하지 않습니다
btsenddata.setOnClickListener(new Button.OnClickListener() {
public void onClick (View v){
AlertDialog.Builder alt_bld = new AlertDialog.Builder(getApplicationContext()); // I've tried with "activity1.this" instead "getApplicationContext()" but it is the same result
alt_bld.setMessage("Do you want to close this window ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Title");
// Icon for AlertDialog
alert.setIcon(R.drawable.icon);
alert.show();
}});
}
.... 내가 그 메소드 getApplicationContext()가 몇 가지 문제를 만들고 있지만 activity.this로 대체하려고 시도했지만 어쨌든 작동하지 않는다고 들었습니다. 누군가가 이것에 대한 이유를 알고 있다면 alertdialogs는 답을줍니다. 감사합니다. .