RSS

Creating a Dialog from code

13 Jul

In my earlier blogpost I mentioned something about a dialog. Here is how to build one:

                        Dialog d =new Dialog(this);
			d.setTitle("Oh Yeah!!");
			TextView tv =new TextView(this);
			tv.setText("This is a dialog");

			d.setContentView(tv);
			d.show();

In the above code snippet what is happening is; an instance of the Dialog class is created which takes in a context(this):

Dialog d =new Dialog(this);

The title is set:

d.setTitle("Oh Yea!!");

Make an instance of the TextView which takes a context of this and set its text. This will form the body of the dialog.


TextView tv =new TextView(this);
tv.setText("This is a dialog");

Add the TextView to the dialog and show it to the user


d.setContentView(tv);
d.show();

Advertisements
 
Leave a comment

Posted by on July 13, 2012 in Uncategorized

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: