【发布时间】:2016-06-18 13:53:45
【问题描述】:
我有一个自定义 DialogFragment,其布局仅包含一个 EditText 元素。
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/reminder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder_message"
android:inputType="text" />
</LinearLayout>
代码:
public class ReminderDialog extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_reminder, container, false);
return rootView;
}
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
if (onDismissListener != null) {
String text = (String) ((TextView) (rootView.findViewById(R.id.reminder))).getText();
onDismissListener.onDismiss(text);
}
}
它在应用程序模块中运行良好。但我想进入图书馆模块。但是后来我调试了错误,那是因为 R.id.reminder 为 0。
无论如何都可以访问该元素。
【问题讨论】:
-
你想做什么?为什么你在 ondismiss 中访问它
-
我长按地图标记的 InfoWindow 并打开一个具有 EditText 元素的 DialogFragment。我不想有任何提交按钮。一旦用户关闭对话框,就会在 InfoWindow 中设置文本。
标签: android android-dialogfragment android-library dialogfragment