Android: Dialog Dismisses Without Calling Dismiss
I have a dialog which performs some validation (below). Thee problem is, the dialog is dismissed after the Toast is displayed, without me calling dismiss. I need to show the toast
Solution 1:
My guess is that you are not creating and showing dialog as mentioned in the Android docs here http://developer.android.com/guide/topics/ui/dialogs.html using OnCreateDialog functions
Please do as mentioned in the docs and let us know if it still does not work.
Solution 2:
I think whatever you are trying to achieve is not possible with AlertDialog.bilder instead of that you can make
- object of Dialog.
- Set your layout for your dialog.
- Set the appropriate listener.
Example.
dialog_view.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><EditTextandroid:layout_height="wrap_content"android:id="@+id/EditText01"android:layout_width="300dip"android:ellipsize="none"/><LinearLayoutandroid:id="@+id/LinearLayout01"android:layout_width="wrap_content"android:layout_height="wrap_content"><Buttonandroid:id="@+id/Button01"android:layout_height="wrap_content"android:text="Yes"android:layout_width="100dip"/><Buttonandroid:id="@+id/Button02"android:layout_height="wrap_content"android:text="No"android:layout_width="100dip"/></LinearLayout></LinearLayout>
Help.java
publicclassHelpextendsActivity {
/** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
d = newDialog(Help.this,
android.R.style.Theme_InputMethod);
createMyDialog();
}
private Dialog d;
privatevoidcreateMyDialog() {
d.setContentView(R.layout.dialog_view);
Buttonb1= (Button)findViewById(R.id.Button01);
Buttonb2= (Button)findViewById(R.id.Button02);
EditTextt= (EditText) findViewById(R.id.EditText01);
OnTouchListenerlistner1=null;
OnTouchListenerlistner2=null;
b1.setOnTouchListener(listner1);
b2.setOnTouchListener(listner2);
listner1 = newOnTouchListener() {
@OverridepublicbooleanonTouch(View v, MotionEvent event) {
// TODO Auto-generated method stubreturnfalse;
}
};
listner2 = newOnTouchListener() {
@OverridepublicbooleanonTouch(View v, MotionEvent event) {
// TODO Auto-generated method stubreturnfalse;
}
};
d.show();
}
}
Post a Comment for "Android: Dialog Dismisses Without Calling Dismiss"