Thursday, September 1, 2011

Two layouts to be loaded for single activity

Two layouts to be loaded for single activity with custom dialog

How to display a custom dialog in your Android application
Yesterday Jozsi showed you, how to make an alert dialog, today I'm going to show you, how to make a custom dialog/popup window.
Sometimes, it's better to make your own dialog, because this way, you can display whatewer you want., the way you want it.
First, make your own layout, with the needed elements. Here, I'm going to use two buttons, a textview inside a scrollview, and an imageview...


  public class main extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            //set up main content view
            //this button will show the dialog
            Button button1main = (Button) findViewById(;
            button1main.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    //set up dialog
                    Dialog dialog = new Dialog(main.this);
                    dialog.setTitle("This is my custom dialog box");
                    //there are a lot of settings, for dialog, check them all out!
                    //set up text
                    TextView text = (TextView) dialog.findViewById(;
                    //set up image view
                    ImageView img = (ImageView) dialog.findViewById(;
                    //set up button
                    Button button = (Button) dialog.findViewById(;
                    button.setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {
                    //now that the dialog is set up, it's time to show it    

No comments:

Post a Comment

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...