Ошибка AlertDialog для Android
Я пытаюсь создать AlertDialog
, но я получаю некоторые ошибки. Диалог отображается, когда пользователь нажимает ListView
вещь.
Здесь AlertDialog
функция:
private void showNewNotebookDialog() {
LayoutInflater inflater = this.getLayoutInflater();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setView(inflater.inflate(R.layout.notebook_new, null));
dialogBuilder.setCancelable(true);
dialogBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = dialogBuilder.create();
dialog.show();
}
А вот и notebook_new.xml
файл:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/notebook_new_parent"
android:layout_width="fill_parent"
android:layout_height="100dp">
<TextView android:text="New notebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<EditText android:id="@+id/notebook_new_edittext"
android:hint="Enter a title"
android:layout_width="match_parent"
android:maxLines="1"/>
</RelativeLayout>
И ошибки:
<VM does not provide monitor information>
PhoneLayoutInflater(LayoutInflater).inflate(int, ViewGroup, boolean) line: 399
PhoneLayoutInflater(LayoutInflater).inflate(int, ViewGroup) line: 353
MainActivity.showNewNotebookDialog() line: 112
MainActivity.access$0(MainActivity) line: 107
MainActivity$1.onItemClick(AdapterView, View, int, long) line: 70
ListView(AdapterView).performItemClick(View, int, long) line: 301
ListView(AbsListView).performItemClick(View, int, long) line: 1283
AbsListView$PerformClick.run() line: 3076
AbsListView$1.run() line: 4149
Handler.handleCallback(Message) line: 615
ViewRootImpl$ViewRootHandler(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 137
ActivityThread.main(String[]) line: 4921
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 1038
ZygoteInit.main(String[]) line: 805
NativeStart.main(String[]) line: not available [native method]
2 ответа
Вы скучаете по android:layout_height
директива для вашего EditText
составная часть. Вам нужно что-то вроде:
<EditText android:id="@+id/notebook_new_edittext"
android:hint="Enter a title"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:maxLines="1"/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/notebook_new_parent"
android:layout_width="fill_parent"
android:layout_height="100dp">
<TextView android:text="New notebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<EditText android:id="@+id/notebook_new_edittext"
android:hint="Enter a title"
android:layout_width="match_parent"
android:layout_height="match_parent" <!-- you are missing this line -->
android:maxLines="1"/>
</RelativeLayout>