problem with Alert Dialog

Tutorials with advanced 'difficulty' and more Lines of Code.

problem with Alert Dialog

Postby lamia » Tue May 18, 2010 4:15 pm

Hi,
i want the content of the dialogue message to be change in different click .I have used onCreateDialog() function,but the problem is from the 2nd time the dialogue is shown with old data.

please help me .Its urgent.
lamia
Freshman
Freshman
 
Posts: 4
Joined: Wed Mar 10, 2010 10:52 am

Top

Re: problem with Alert Dialog

Postby uncre8d1 » Tue Jun 08, 2010 4:20 am

Best way I can think of is either a) launch a second dialog or b) setup your dialog to check for a passed parameter (i.e. add a new parameter like 'int mode' or something). If you do that second one, you can use a switch statement to direct your program to set msg1 or msg2 in the dialog...
Normal?!? Man, I'd give my left arms to be normal.
User avatar
uncre8d1
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Mar 16, 2010 3:41 am
Location: Silver Spring, MD

Re: problem with Alert Dialog

Postby lamia » Tue Jun 08, 2010 9:59 am

hello,thx for the reply,I used the alert in other way,so that I don't need to change it's content.

thx a lot.
lamia
Freshman
Freshman
 
Posts: 4
Joined: Wed Mar 10, 2010 10:52 am

Re: problem with Alert Dialog

Postby crandf » Mon Feb 14, 2011 7:22 am

I had that problem too, can't remember exactly how I solved it, but its either:
1) If you have used "dialog.show();" for that dialog, then insert in the line "dialog.dismiss();" immediately under it.
2) If you only have a few fixed messages, try using separate xml files for each.
crandf
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Feb 14, 2011 7:10 am

Re: problem with Alert Dialog

Postby strider2023 » Wed Feb 23, 2011 12:37 pm

Hi lamia,

If you want to change the content of your Dialog (guessing that you have your own custom dialog) just do the set the text view of your dialog box to the new text you want to display without dismissing it i.e. dialog.dismiss(). Check for the line where I have set the text view to change and removed the dismiss command. :D

Code: Select all
/**
    * This is the function to display custom dialog box with scroll-able text content.
     * @param title - Title of the the dialog box displayed as the header
     * @param body_text - Body of the dialog box displayed as the body of the dialog box with relevant details.
    * @param context
    */
    public static void createDialog(String title, String body_text, Context context) {
       //Create the dialog.
          final Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.diet_app);
        dialog.setTitle(title);
        dialog.setCancelable(true);
       
        //Set up text
        final TextView text = (TextView) dialog.findViewById(R.id.diet_app_body);
        text.setText(body_text);
       
        //Set up image
        ImageView img = (ImageView) dialog.findViewById(R.id.diet_app_ImageView01);
        img.setImageResource(R.drawable.logo);
       
        //Set up button
        Button button = (Button) dialog.findViewById(R.id.diet_app_yesbtn);
        button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
              text.setText("Changed");
              //dialog.dismiss();
            }
        });   
       
        Button button_1 = (Button) dialog.findViewById(R.id.diet_app_cancelbtn);
        button_1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
              dialog.dismiss();
            }
        }); 
       
        dialog.show();
    }


Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="280px"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/diet_app_ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<ScrollView
android:id="@+id/dialog_scroll"
android:layout_width="wrap_content"
android:layout_below="@+id/diet_app_ImageView01"
android:layout_height="200px">
<TextView
android:id="@+id/diet_app_body"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</TextView>
</ScrollView>
<AbsoluteLayout
android:id="@+id/widget31"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/dialog_scroll"
>
<Button android:id="@+id/diet_app_yesbtn"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="Save"
android:layout_x="30px"
android:layout_y="0px"
android:textStyle="normal|bold"
android:textColor="#343434"
/>
<Button android:id="@+id/diet_app_cancelbtn"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_x="160px"
android:layout_y="0px"
android:textStyle="normal|bold"
android:textColor="#343434"
/>
</AbsoluteLayout>
</RelativeLayout>
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests