Note that there are some explanatory texts on larger screens.

plurals
  1. POGet reference to widgets and set its event handlers on AlertDialog created using custom XML layout
    text
    copied!<p>I have created AlertDialog, which has some buttons and a gridview, from layout using <code>LayoutInflater</code>, and have overridden <code>onCreateDialog()</code> in my Activity class, where it packs in the layout and returns <code>Dialog</code> object.</p> <p>And in <code>onCreate()</code> method of the activity class, I show the dialog using <code>showDialog(id)</code> where id is the constant that is associated with a particular dialog.</p> <p>Now, I want to bind click events to the widgets I have on the AlertDialog which is just shown. I do it as follows:</p> <pre><code>showDialog(DLG_INPUT_FORM); inputform = new Dialog(MyActivity.this); inputform.setContentView(R.layout.input_form); edtName = (EditView) inputform.findViewById(R.id.edtName); btnCheck = (Button) inputform.findViewById(R.id.btnCheck); txtStatus = (TextView) inputform.findViewById(R.id.txtStatus); //This event is never triggered. btnCheck.setOnClickListener(new OnClickListener() { public void onClick(View v) { String name = edtName.getText().toString(); //Do Something with the "name" txtStatus.setText("Available"); } }); </code></pre> <p>This doesn't throw any exception, but clicking on buttons doesn't do anything, in fact event is not triggered at all.</p> <p>What is wrong in the code?</p> <p><strong>UPDATE:</strong></p> <p>The issue is kind of similar to <a href="https://stackoverflow.com/questions/4113939/handling-buttons-in-custom-dialogs/">this</a>, I'm also getting reference to widgets on Dialog for <code>btnCheck</code> and <code>txtStatus</code> but something is wrong with click event that it doesn't work.</p>
 

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