Dialog problem

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


Sponsored Links
 Hello,

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?

regards
Andr

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;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        showDialog(DIALOG_NEW2);
    }
    protected Dialog onCreateDialog(int id) {
        Context mContext = getApplicationContext();
        Dialog dialog = new Dialog(mContext);
        switch(id) {
        case DIALOG_NEW:
                dialog.setContentView(R.layout.popup_new);
                dialog.setTitle("Custom Dialog");

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

                TextView text2 = (TextView) dialog.findViewById(R.id.text);
                text2.setText("Hello, this is a custom dialog!2");
            break;
        default:
            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
 http://sites.google.com/site/rezmobileapps/treking 

--



Dialog problem

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


 Really?

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
'this'.






--



Dialog problem

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


 More stars/occurrences on the bug report welcome:
 http://code.google.com/p/android/issues/detail?id=5748 






--



Other Threads

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

Hi,
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?

Thanks,
Stephan

-- 

2. 100 chances to win Google IO tickets

http://googlecode.blogspot.com/2011/03/last-call-for-google-io.html

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