starizard
starizard

Reputation: 531

How to create a popup window with spinner for android?

I would like to create a popup window which will appear the first time the user opens the application and ask the user to select the setting within a spinner (example something close like the picture below)

image
(source: mikesandroidworkshop.com)

Also, I would like it to popup automatically rather then having the need to press on a button. Is it possible to do so?

Please help. thanks a lot. =)

Upvotes: 0

Views: 8435

Answers (2)

Sver
Sver

Reputation: 3409

Just call it onCreate, for example. And use shared preferences to check for first time launch.

private void showSettingsPopUpOnFirstTimeLaunch(){

        SharedPreferences settings = this.getSharedPreferences("default", 0);
        boolean firstStart =  settings.getBoolean("firstStart", true);

        if(firstStart){
        showPopUp(); // 
        }
    }

And when closing popup just change flag in SharedPreferences (you would probably will want to make popup not-cancelable).

SharedPreferences settings = this.getSharedPreferences("default",
                0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("firstStart", false);
        editor.commit();

Upvotes: 0

skynet
skynet

Reputation: 9908

That is called a Dialog. See this page for more info http://developer.android.com/guide/topics/ui/dialogs.html.

To create the one like you showed, look under the Custom Dialog section. Basically create the layout you want to see inside of the dialog in an XML file and use setContentView as you would with an activity.

If you want it to pop up when an activity starts just put the code in the onStart method in your activity.

Upvotes: 2

Related Questions