2012-02-24 4 views
0

대화 상자가있는 환경 설정 활동을 만들었습니다. 대화 상자에는 CANCEL 및 ADD라는 두 개의 버튼이 있습니다. 추가 버튼을 클릭하면 MAC 주소와 장치 이름을 입력 할 수있는 편집 대화 상자가 두 개있는 대화 상자가 열립니다.환경 설정 대화 상자에서 대화 버튼에 액세스하는 방법

환경 설정 대화 상자에서 버튼을 클릭하면 어떻게 처리 할 수 ​​있습니까? 대화 상자를 클릭 할 때 액세스 할 수 있으면 다른 활동을 열 수 있습니다.

답변

1

대화 상자의 모든 기본 버튼에 대해 DialogInterface.OnClickListener을 제공 할 수 있습니다.

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setMessage("Are you sure you want to exit?") 
     .setCancelable(false) 
     .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       MyActivity.this.finish(); 
      } 
     }) 
     .setNegativeButton("No", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       dialog.cancel(); 
      } 
     }); 
AlertDialog alert = builder.create(); 

다른 방법으로 할 수 있습니다 create your own dialog, with a custom layout 당신이 원하는대로 위젯 표시 : 여기 developer.android.com에 Dialogs topic에서 복사 - 붙여 넣기입니다. 이 방법을 사용하면 버튼에 일반 View.OnClickListener을 연결하고 로직을 입력 할 수 있습니다.

+0

답장을 보내시겠습니까? – user1106888

관련 문제