Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在对话框中放置额外数据?_Android_Dialog - Fatal编程技术网

Android 如何在对话框中放置额外数据?

Android 如何在对话框中放置额外数据?,android,dialog,Android,Dialog,我想为dialog.setOnCancelListener(OnCancelListener)注册回调, 但是这个回调会为其他对话框注册很多次,所以我应该从传递的对话框中获取一些唯一的日期,并使用不同的额外日期来知道哪个是有用的还是无用的。使用一个接口,将此代码放在您的对话框框架中: 公共静态接口MyInterface{ 公共无效cance(字符串someInfo); } 然后,在onCancel方法中: @Override public void onCancel(DialogInterfac

我想为
dialog.setOnCancelListener(OnCancelListener)
注册回调,
但是这个回调会为其他对话框注册很多次,所以我应该从传递的对话框中获取一些唯一的日期,并使用不同的额外日期来知道哪个是有用的还是无用的。

使用一个接口,将此代码放在您的对话框框架中: 公共静态接口MyInterface{ 公共无效cance(字符串someInfo); }

然后,在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
}

函数onAttach是在哪里定义的?当您看到@Override时,这意味着它是从超类继承的方法。本质上,onAttach是接口类的一部分,就像onCreate是Activity类的一部分一样。
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
}