Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a custom AlertDialog View
    primarykey
    data
    text
    <p>In the <a href="http://developer.android.com/reference/android/app/AlertDialog.html" rel="noreferrer">Android docs on AlertDialog</a>, it gives the following instruction and example for setting a custom view in an AlertDialog:</p> <p><Blockquote>If you want to display a more complex view, look up the FrameLayout called "body" and add your view to it:</Blockquote></p> <pre><code>FrameLayout fl = (FrameLayout) findViewById(R.id.body); fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT)); </code></pre> <p>First off, it's pretty obvious that <code>add()</code> is a typo and is meant to be <code>addView()</code>.</p> <p>I'm confused by the first line using R.id.body. It seems that it's the body element of the AlertDialog ... but I can't just enter that in my code b/c it gives a compile error. Where does R.id.body get defined or assigned or whatever?</p> <p>Here's my code. I tried to use <code>setView(findViewById(R.layout.whatever)</code> on the builder but it didn't work. I'm assuming because I didn't manually inflate it?</p> <pre><code>AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Title") .setCancelable(false) .setPositiveButton("Go", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { EditText textBox = (EditText) findViewById(R.id.textbox); doStuff(); } }); FrameLayout f1 = (FrameLayout)findViewById(R.id.body /*CURRENTLY an ERROR*/); f1.addView(findViewById(R.layout.dialog_view)); AlertDialog alert = builder.create(); alert.show(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload