Hi, I am trying to create a simple alert dialog that just shows the
user input. However, android appears to be caching the dialog and so
the text in the dialog stays static after the first initialization.

My codes are as followed, it has one button, one editable text, and
when you click on the button, it's supposed to popup a dialog that
shows the same text as it was enter in the textbox.

However, the text will stay static after the first click, when the
dialog box is closed and reopened, the same text appear regardless of
the text in the textbox

Can someone tell me how to make it work the way i wanted it to?

Thanks,

public class Test extends Activity {

    private static final int DIALOG_ID = 1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btn = (Button)findViewById(R.id.test);

        btn.setOnClickListener(new android.view.View.OnClickListener()
{
          @Override
          public void onClick(View v) {
            showDialog(DIALOG_ID);
          }});
    }




    @Override
    protected Dialog onCreateDialog(int id) {
      if(id == DIALOG_ID){
        EditText mytext = (EditText)findViewById(R.id.mytext);
        return new AlertDialog.Builder(Test.this)
        .setTitle(mytext.getText().toString())
        .setPositiveButton("OK", new OnClickListener(){
          public void onClick(DialogInterface dialog, int which) {}})
        .create();
      }

      return null;
    }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

   <EditText
           android:id="@+id/mytext"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:background="@android:drawable/editbox_background"/>
 <Button
        android:id="@+id/test"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="TEST"/>

</LinearLayout>

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

Reply via email to