我的应用程序中有一个自定义对话框。我的自定义对话框实现为具有透明背景和类似对话框 View 的 Activity 。 Mu 自定义对话框看起来像警报对话框,带有标题、消息和按钮。我正在尝试做的是创建一个漂亮的界面来设置我的弹出窗口的标题、消息和 onClickListener。
首先,我想让所有员工都像这样:
Intent intent = new Intent (this, CustomPopup.class);
intent.putExta ("Title", "PopupTitle");
intent.putExta ("Message", "PopupMessage");
intent.putExtra ("OnCLickListener", ?????); //here is problem
startActivity(intent);
但问题是无法将 OnCLickListener 用于 Intent 。
其次,我尝试创建实现 Parcable 的类。 但是问题是一样的
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(title);
dest.writeString(message);
dest.writeValue(buttonClickListener); // here is problem. I cannot write Interface
}
我无法将 OnCLickListener 写入 Parcel 对象。
如何成为?如何为我的自定义弹出窗口编写漂亮的界面?因为弹出窗口可以有不同的标题和消息,并且弹出窗口将用于许多 Activity ....提前致谢
最佳答案
创建一个同时实现 OnClickListener 和 Serializable 的类。通过 Intent 向“对话框”发送一个实例。
关于Android:将接口(interface)放入 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12963662/