我想为dialog.setOnCancelListener ( OnCancelListener)
注册一个回调,
但是这个回调将被多次注册用于其他对话框,所以我应该从传递的对话框中获取一些具有不同额外日期的唯一日期,以了解哪一个是有用的或无用的。
答案 0 :(得分:0)
使用界面,将此代码放入Dialog Fragmnet: public static interface MyInterface { public void cance(String someInfo); }
private MyInterface mListener;
@Override
public void onAttach(Activity activity) {
mListener = (MyInterface) activity;
super.onAttach(activity);
}
@Override
public void onDetach() {
mListener = null;
super.onDetach();
}
然后,在onCancel方法中:
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
super.onCancel(dialog);
//This line passes the String to the implementing class
mListener.onChoose(choice);
}
回到班上:
public class MainActivity extends Activity implements MyInterface {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
public void onChoose(String myExtraData) {
//Do stuff here
}