마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 custom dialog에서 .dismiss(); 명령어가 안먹어요

0 추천
protected void onCreate(Bundle savedInstanceState) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
 final View layout = inflater.inflate(R.layout.custom, (ViewGroup) findViewById(R.id.btn1));;
 AlertDialog.Builder builder = new AlertDialog.Builder(this);
 builder.setTitle("안내");
builder.setView(layout);
 builder.setCancelable(false);
 Button bin4 = (Button) layout.findViewById(R.id.btn4);
 bin4.setOnClickListener(new View.OnClickListener()
 {
 @Override
 public void onClick(View v)
 {
 CheckBox chk1 = (CheckBox) layout.findViewById(R.id.chk1);
 CheckBox chk2 = (CheckBox) layout.findViewById(R.id.chk2);
 CheckBox chk3 = (CheckBox) layout.findViewById(R.id.chk3);
 if(chk1.isChecked() && chk2.isChecked() && chk3.isChecked()){

//builder.dismiss();

}else {
 Toast.makeText(getApplicationContext(), "모든 약관을 동의해주세요", Toast.LENGTH_SHORT).show();
 }
 }
 });
 builder.create().show();

...

}

 

로 코드를 작성했는데 다이얼로그가 종료가 안되요 ㅜ
안드로이드 님이 2016년 9월 18일 질문

1개의 답변

0 추천

builder의 사용법이 정확하지 않습니다.

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.dialog_fire_missiles)
               .setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // FIRE ZE MISSILES!
                   }
               })
               .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       // User cancelled the dialog
                   }
               });
        // Create the AlertDialog object and return it
        return builder.create();

위의 코드처럼 postivie button, negative button에 callback 처리를 해주셔야 합니다.

해당 콜백 안에서 dialog.dismiss()로 닫으시면 됩니다.

익명사용자 님이 2016년 9월 18일 답변
...