Tof*_*ira 11 android dialog custom-controls
我正在开发一个小程序,我需要添加一个自定义对话框,在关闭时将一些信息传递给调用活动.我扩展了对话框类,当我尝试在关闭时捕获自定义对话框时,使用onDismiss侦听器,它永远不会到达它,因为我使用了自定义对话框.
这是我活动的一部分 -
.
.
.
attributes customizeDialog = new attributes(con,position,pick.getLastVisiblePosition());
customizeDialog.show();
Run Code Online (Sandbox Code Playgroud)
(属性是扩展对话框类的类的名称).
这是我在对话框完成时设置的事件监听器 -
customizeDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Log.v("LOG_CAT",attributes.selectedIndexes.get(0) + " " + attributes.selectedIndexes.get(1) + " " + attributes.selectedIndexes.get(2) + " " + attributes.selectedIndexes.get(3) + " " + attributes.selectedIndexes.get(5) + " ");
}
});
Run Code Online (Sandbox Code Playgroud)
我知道我做错了,我只是不知道如何解决它.
我真的很感激这个问题的任何帮助.
谢谢!
Squ*_*onk 18
我倾向于让我的活动实现像这样的听众......
public class MyActivity extends Activity
implements DialogInterface.OnDismissListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
attributes customizeDialog = new attributes(con,position,pick.getLastVisiblePosition());
customizeDialog.setOnDismissListener(this);
customizeDialog.show();
}
@Override
public void onDismiss(DialogInterface dialog) {
// Do whatever
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以让您的调用活动实现在对话框关闭时调用的自定义侦听器接口:
public interface MyDialogListener {
void OnCloseDialog();
}
public class MyActivity implements MyDialogListener {
public void SomeMethod() {
MyDialog myDialog = new MyDialog(this, this);
myDialog.show();
}
public void OnCloseDialog() {
// Do whatever you want to do on close here
}
}
public class MyDialog extends Dialog {
MyDialogListener mListener;
public MyDialog (Context context, MyDialogListener listener) {
super(context, R.style.Dialog);
mListener = listener;
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.CloseButton:
mListener.OnCloseDialog();
dismiss()
break;
default:
//...
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果您想在解雇之外的任何其他时间将内容发送回呼叫者,这将特别有用.
归档时间: |
|
查看次数: |
22429 次 |
最近记录: |