This thread prove to be very useful, Thanks all;
her my question is;
in my dialog I have a simple input field that takes user email; with two buttons 1. "Submit ", 2. "Cancle"
and I need to control the dialog dismiss operation.
below attached code do not have any dismiss() function call, But either i press cancle or Submit Dialog gets disapper. I need to control the dialog hide/show during email validation.
This is the Layout XML "alert_email_subscription"
Using xml Syntax Highlighting
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:text="@string/email_title"
android:gravity="left"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText
android:id="@+id/emailEditTextNew"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:scrollHorizontally="true"
android:singleLine="true"
android:autoText="false"
android:capitalize="none"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</LinearLayout>
Parsed in 0.003 seconds, using
GeSHi 1.0.8.4
- LayoutInflater factory = LayoutInflater.from(Main.this);
- final View textEntryView = factory.inflate(R.layout.alert_email_subscription, null);
-
- AlertDialog d = new AlertDialog.Builder(Main.this)
- .setIcon(R.drawable.android_icon)
- .setTitle(getString(R.string.email_toptitle))
- .setCancelable(false)
- .setView(textEntryView)
- .setNeutralButton(
- getText(R.string.submit_button_text),// Label
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- EditText emailEditText = (EditText) textEntryView.findViewById(R.id.emailEditTextNew);
- String email = emailEditText.getText().toString().trim();
- Log.d(Tag, "Email is :: " + email);
- if ( email.equals("")) {
- Log.d(Tag, "Provide the email");
- //((AlertDialog.Builder)dialog).setMessage("Provide the email");
- // HERE I need to STOP closing the Dialog;
- }
- else if(ClientUtil.validateEmail(email)){
- Log.d(Tag, "Invalid email");
- //((AlertDialog.Builder)dialog).setMessage("Invalid email");
- // HERE I need to STOP closing the Dialog;
- } else {
- subscribeEmail(email);
- }
- }
- }
- )
- .setNegativeButton(
- getText(R.string.cancel_button_text),// Label
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- finish();
- }
- }
- )
- .create();
- d.show();