Dialog problem

by Andr茅 » Wed, 10 Feb 2010 05:24:51 GMT

Sponsored Links

I'm trying to make a dialog box to open when I start a program.
Eclipse likes my code, I like my code =), but the emulator does not
like my code. It says that something went totally worong and the
application has to shut  down. Bellow you can see my code. When I run
it in debug mode everything seems to go as it should but when it gets
to "return dialog; " eclipse debug windows says source not found.
Anyone have any suggestions?


package com.test.popup;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

public class popup extends Activity {
        static final int DIALOG_NEW = 0;
        static final int DIALOG_NEW2 = 1;

    public void onCreate(Bundle savedInstanceState) {
    protected Dialog onCreateDialog(int id) {
        Context mContext = getApplicationContext();
        Dialog dialog = new Dialog(mContext);
        switch(id) {
        case DIALOG_NEW:
                dialog.setTitle("Custom Dialog");

                TextView text = (TextView) dialog.findViewById(R.id.text);
                text.setText("Hello, this is a custom dialog!");
        case DIALOG_NEW2:
                dialog.setTitle("Custom Dialog");

                TextView text2 = (TextView) dialog.findViewById(R.id.text);
                text2.setText("Hello, this is a custom dialog!2");
            dialog = null;
        return dialog;


Dialog problem

by Andr茅 » Wed, 10 Feb 2010 05:33:18 GMT

 Oooh, I tried to follow this explanation:

 http://developer.android.com/intl/de/guide/topics/ui/dialogs.html #CustomDialog

if anyone wants to have a look at it!


Sponsored Links

Dialog problem

by TreKing » Wed, 10 Feb 2010 05:33:25 GMT


You're probably seeing something about a BadToken in the debug log, yes?
DO NOT use getApplicationContext(). Use your current activity or the context
from one of your views.

I swear someone runs into this every single day ...

TreKing - Chicago transit tracking app for Android-powered devices


Dialog problem

by Andr茅 » Wed, 10 Feb 2010 05:39:37 GMT


Yeah, now I saw your other replies. You are the man! Thanks!


Dialog problem

by Bob Kerns » Wed, 10 Feb 2010 07:05:19 GMT

 The four stages of Android UI Enlightenment:

0) You dutifully use getApplicationContext() his Activity to pass
along to the SDK.
1) You realize you don't NEED to call getApplicationContext() from
your Activity to pass along, 'this' should work.
2) You realize it is WRONG to call getApplicationContext() from your
Activity to pass along, because that's not the right context to pass
along -- your Activity is.
3) You wonder why the documentation and various failing examples keep
saying to use getApplicationContext()?
4) I am still stuck at stage 3. Can you enlighten me?

Really, can't someone take a half-hour and go through all the
occurrences of getApplicationContext() in documentation, Javadoc, and
examples, and fix them? Except for the Javadoc for
getApplicationContext(), nearly all occurrences should probably be


Dialog problem

by Lance Nanek » Wed, 10 Feb 2010 09:58:04 GMT

 More stars/occurrences on the bug report welcome:


Other Threads

1. How to set ImageView from internal storage (or SDCard)

my app displays some pictures I want to replace at certain intervals by
downloading them from a webpage.
I can set the image from my drawable folder, assets folder or by downloading
it from a webpage:

ImageView im = (ImageView) findViewById(R.id.SplashLogo);
                // url = "file:///android_asset/pic.png";
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");

What I want, however, is to display an image that I downloaded previously to
internal storage (or sdcard if i have to).
So: How do set the filename/folder to point to internal storage?



2. 100 chances to win Google IO tickets


Read this blog entry by Vic Gundotra: "Last Call for Google I/O"

-John Coryat


3. How to get "arrow icon" selector between two fragments.

4. Phone gap

5. TextView gravity off on Galaxy Tab?

6. how to integrate s/w codec like h/w codec (omx plugin) into stagefright

7. Masih bingung pilih HH