如何将值传递回自定义选择Dialog类的活动?...我有一个应用程序单击图像将出现一个对话框类,我将选择一个值..i需要更新后面活动中的这些值..可以有人建议我吗?自定义对话框在android中传递值
0
A
回答
0
如果您的对话框是一个主题声明为对话框的活动,您应该检查如何在活动中使用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();
}
});
}
}
当你想用你的对话框中,可使用设置在您的电话活动的价值回调构建它
相关问题
- 1. android自定义对话框
- 2. Android自定义对话框
- 3. Android自定义对话框
- 4. 自定义对话框Android
- 5. 在android中的自定义对话框?
- 6. 取代facebook对话框中的自定义对话框在android
- 7. android asynctask中的自定义对话框
- 8. 在自定义对话框的Android
- 9. Android:自定义提醒对话框出现在DEFULT对话框
- 10. Android - 从另一个自定义对话框显示自定义对话框
- 11. 如何在Android中自定义ANR对话框而不是android ANR对话框
- 12. Android自定义列表对话框
- 13. Android的对话框自定义样式
- 14. android自定义对话框错误
- 15. Android自定义形状的对话框
- 16. 与Android的自定义对话框
- 17. Android自定义对话框高度
- 18. Android自定义对话框不工作
- 19. Android的自定义微调对话框
- 20. 自定义对话框成为Android的
- 21. Android自定义对话框的Datepicker
- 22. Android自定义进度对话框
- 23. 自定义对话框不显示 - Android
- 24. Android自定义对话框图像
- 25. Android的自定义对话框的EditText
- 26. Android自定义对话框不显示
- 27. Android自定义弹出对话框
- 28. android自定义对话框背景
- 29. Android自定义进度对话框webview
- 30. Android - 自定义对话框太大