problem in creating popup window

Put your problem here if it does not fit any of the other categories.

problem in creating popup window

Postby tcsakthimai » Thu Jan 20, 2011 1:51 pm

I need to create popup window in android screen.

please give me a sample code to create popup window.

Thanks in advance.
tcsakthimai
Developer
Developer
 
Posts: 40
Joined: Wed Jan 19, 2011 2:21 pm

Top

Re: problem in creating popup window

Postby vengeance_mj » Thu Jan 20, 2011 8:52 pm

Copied from the Android SDK documentation.

Code: Select all
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
       .setCancelable(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                MyActivity.this.finish();
           }
       })
       .setNegativeButton("No", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
           }
       });
AlertDialog alert = builder.create();


Here is a link for u
http://developer.android.com/guide/topics/ui/dialogs.html
vengeance_mj
Senior Developer
Senior Developer
 
Posts: 174
Joined: Thu Oct 29, 2009 2:32 am

Re: problem in creating popup window

Postby tcsakthimai » Fri Jan 21, 2011 9:58 am

Thanks for your reply.

But i am asking to create popup window. U gave me a solution for alertdialog.

I used the below solution but i got force close error.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Test Pop-Up"
/>

</LinearLayout>
Java code:
LayoutInflater inflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PopupWindow pw = new PopupWindow(
inflater.inflate(R.layout.popup_example, null, false),
100,
100,
true);
// The code below assumes that the root container has an id called 'main'
pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);

Is there any other solution to solve this problem?
tcsakthimai
Developer
Developer
 
Posts: 40
Joined: Wed Jan 19, 2011 2:21 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 24 guests