Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling buttons in custom dialogs
    primarykey
    data
    text
    <p>I have a little problem with an android custom dialog.</p> <p>I construct a custom dialog in the onCreateDialog(int) function:</p> <pre><code>dialog = new Dialog(this); dialog.setContentView(R.layout.custom_dialog); dialog.setTitle("Custom Dialog"); </code></pre> <p>I have a onClick(View) function in the same class:</p> <pre><code> public void onClick(View v) { switch(v.getId()) { case R.id.dialog_button: Log.i("pma57","dialog button pressed"); break; case R.id.main_button: showDialog(DIALOG_CUSTOM); break; } } </code></pre> <p>This is the XML definition:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingBottom="20dp"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/enter_username" /&gt; &lt;EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;Button android:id="@+id/dialog_button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="OK" android:onClick="onClick" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>The Dialog shows up. But the Button does not work (the app crashs)- which is quite ok because the onClick-function for the callback is defined in my main activity - and the dialog is a new activity (am I right?).</p> <p>But I realy don't know how i implement a button in the dialog - I think this is a fundamental understanding problem of the technic. The long way would be to subclass Dialog and write everything there - but is there another way which I don't see?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    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