I want to display a custom alert dialog whose structure has been defined in an XML file. This is the code I used.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(findViewById(R.layout.inputform));
builder.show();
It is fired when a button is clicked. However, the window was not getting displayed. I got this transparent grey layer on top of the screen and could not click on anything. Some basic codes like using setMessage
or displaying checkboxes work well, though. Can anyone point out where I do wrong?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="Room name" android:id="@+id/TextView01"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<EditText android:hint="Enter room name" android:id="@+id/EditText01"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1"/>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="Point id" android:id="@+id/TextView02"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<EditText android:hint="Enter point id" android:id="@+id/EditText02"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1"/>
</TableRow>
<TableRow android:id="@+id/TableRow03" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="OK" android:id="@+id/btnOK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</LinearLayout>
Try adding builder.create(); before builder.show().
Simple way to represent dialog...
simple dialog here
try this:
You can use the following class
This is because
findViewById
is for finding a specific view in the current activity´s layout, not for loading a whole layout.You can use @Matt's answer or maybe you can inflate the layout with a LayoutInflater like this:
(Not tried it but I think it should work).