Checked API document just now.
Should override the onPrepareDialog(int id, Dialog dialog) to prepare a
managed dialog before it is being shown.

The following extra codes for my test program makes it works perfectly:
----------------------------------------------------------------------------------
protected void onPrepareDialog(int id, Dialog dialog){
((AlertDialog)dialog).setTitle(errTitle);
((AlertDialog)dialog).setMessage(errMessage);
 }

2009/9/5 王心锋 <kyowxf2...@gmail.com>

> Dialog only one instance in a activity that is the first click;I think
>
> 在 2009-9-5 12:47 PM,"陈增顺" <samuel...@gmail.com> 说:
>
>
> Hi,  I am trying to reuse a dialog to show different message in different
> cases.
>   But it seems that Android will cache the content, when the dialog was
> created.
>
>   Here is my codes, the dialog just show the content set by the the first
> clicked button.
>
> ------------------------------------------------------------------------------------------------------------------------------
>   package com.mytest;
>
> import android.app.Activity;
> import android.app.AlertDialog;
> import android.app.Dialog;
> import android.content.DialogInterface;
> import android.os.Bundle;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
>
> public class myTest extends Activity {
> public static String errTitle = "";
>  public static String errMessage = "";
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>         Button bt1 = (Button)findViewById(R.id.Button01);
>         Button bt2 = (Button)findViewById(R.id.Button02);
>         bt1.setOnClickListener(new OnClickListener(){
>          public void onClick(View v){
>          errTitle = "H1";
>          errMessage = "M1";
>          showDialog(0);
>          }
>         });
>         bt2.setOnClickListener(new OnClickListener(){
>          public void onClick(View v){
>          errTitle = "H2";
>          errMessage = "M2";
>          showDialog(0);
>          }
>         });
>     }
>
> protected Dialog onCreateDialog(int id) {
> AlertDialog dialog = null;
>  switch (id){
> case 0:
> dialog =  new AlertDialog.Builder(this)
>         .setTitle(errTitle)
>         .setMessage(errMessage)
>         .setPositiveButton(
>  "Confirm",
> new DialogInterface.OnClickListener() {
> public void onClick(DialogInterface dialog,
>  int whichButton) {
> dialog.dismiss();
> return;
>  }
> }).create();
> }
>  return dialog;
> }
> }
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to