0

I'm trying to create an AlertDialog, but I'm getting some errors. The dialog is shown when the user click a ListView item.

Here is the AlertDialog function:

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(); } 

And here is the notebook_new.xml file:

<?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> 

And the errors:

<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
  • Could be a problem with this directive android:maxLines="1"? Can you remove it and try again. Commented Nov 27, 2014 at 16:27
  • Else the android:layout_height directive is missing with your EditText component. I am surprised Android Lint hasn't pick up on this. Commented Nov 27, 2014 at 16:39

2 Answers 2

1

You're missing the android:layout_height directive for your EditText component. You need something like:

<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"/> 
Sign up to request clarification or add additional context in comments.

Comments

0
<?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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.