2011-07-30 7 views
0

대화 상자 클래스의 사용자 정의 선택에서 활동으로 값을 전달하는 방법 ... 대화 상자 클래스가 표시되고 하나의 값을 선택하는 이미지를 클릭 할 때 응용 프로그램이 있습니다 .i 다시 활동에서 그 가치를 업데이 트해야합니다. 어떤 사람이 나를 제안합니까?android에서 값을 전달하는 사용자 정의 대화 상자

답변

0

대화 상자가 대화 상자로 선언 된 테마가있는 활동이면 activity에서 startActivityForResult()를 사용하는 방법을 확인해야합니다.
2 단계에서 1 단계로 데이터를 전송할 수 있습니다.

3

대화 상자를 확장하는 클래스를 사용하는 경우 대화 상자 버튼을 클릭 할 때 수행 할 작업에 대한 인터페이스를 추가 할 수 있습니다 호출 액티비티에서 값을 설정) 생성자에서 콜백을 설정한다. 이런 식으로 뭔가 :

final CustomDialog dialog = new CustomDialog(this, new ICustomDialogEventListener() { 
     public void customDialogEvent(int value) { 
      // Do something with the value here, e.g. set a variable in the calling activity 
     } 
    }); 
: 당신이 대화 상자를 사용하려는 경우

public class CustomDialog extends Dialog { 

    // this is your interface for what you want to do on the calling activity 
    public interface ICustomDialogEventListener { 
     public void customDialogEvent(int valueYouWantToSendBackToTheActivity); 
    } 

    private ICustomDialogEventListener onCustomDialogEventListener; 

    // In the constructor, you set the callback 
    public CustomDialog(Context context, 
      ICustomDialogEventListener onCustomDialogEventListener) { 
     super(context); 
     this.onCustomDialogEventListener = onCustomDialogEventListener; 
    } 

    // And in onCreate, you set up the click event from your dialog to call the callback 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     Button btnOk = (Button) findViewById(R.id.customDialogButton); 
     btnOk.setOnClickListener(new Button.OnClickListener() 
     { 
      public void onClick(View v) { 
       onCustomDialogEventListener.customDialogEvent(valueYouWantToSendBackToTheActivity); 
       dismiss(); 
      } 
     }); 
    } 
} 

, 당신은 당신의 전화 활동에 값을 설정하는 콜백을 구성

관련 문제