Note that there are some explanatory texts on larger screens.

plurals
  1. POCan someone get this custom AlertDialog to actually work?
    primarykey
    data
    text
    <p>I asked another question about custom AlertDialog <a href="https://stackoverflow.com/questions/7825720/extending-alertdialogs-in-android-where-to-find-examples-how-to-get-title-and">here</a>.</p> <p>Then I clicked my way to this custom AlertDialog (found <a href="http://www.devdaily.com/java/jwarehouse/apps-for-android/Translate/src/com/beust/android/translate/AboutDialog.java.shtml" rel="nofollow noreferrer">here</a>):</p> <pre><code>import android.app.AlertDialog; import android.content.Context; import android.webkit.WebView; /** * Display a simple about dialog. */ public class AboutDialog extends AlertDialog { protected AboutDialog(Context context) { super(context); setContentView(R.layout.about_dialog); setTitle(R.string.about_title); setCancelable(true); WebView webView = (WebView) findViewById(R.id.webview); webView.loadData("Written by Cédric Beust (&lt;a href=\"mailto:cedric@beust.com\"&gt;cedric@beust.com)", "text/html", "utf-8"); } } </code></pre> <p>I modified like this:</p> <pre><code>import android.app.AlertDialog; import android.content.Context; import android.webkit.WebView; /** * Display a simple about dialog. */ public class AboutDialog extends AlertDialog { protected AboutDialog(Context context) { super(context); setTitle("Test"); setCancelable(true); setContentView(R.layout.paus); } } </code></pre> <p>and then tried to use it, like this:</p> <pre><code>AboutDialog ad = new AboutDialog(getApplicationContext()); ad.show(); </code></pre> <p>But I get this error:</p> <pre><code>android.util.AndroidRuntimeException: requestFeature() must be called before adding content at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181) at com.android.internal.app.AlertController.installContent(AlertController.java:206) at android.app.AlertDialog.onCreate(AlertDialog.java:251) at android.app.Dialog.dispatchOnCreate(Dialog.java:307) at android.app.Dialog.show(Dialog.java:225) at TestPackage.MainActivity$5.onClick(MainActivity.java:382) at android.view.View.performClick(View.java:2538) etc... </code></pre> <p>So I'd like to know why this is happening. </p> <p>===================== EDIT ==========================0</p> <p>As per suggestions below, I modified the code so it looks like this:</p> <pre><code>import android.app.AlertDialog; import android.content.Context; import android.os.Bundle; import android.webkit.WebView; /** * Display a simple about dialog. */ public class AboutDialog extends AlertDialog { protected AboutDialog(Context context) { super(context); } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.paus); } } </code></pre> <p>But I get a <strong>BadTokenException</strong> instead.</p>
    singulars
    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.
    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