Note that there are some explanatory texts on larger screens.

plurals
  1. POAlertDialog Closing Automatically
    primarykey
    data
    text
    <p>I have an <code>AlertDialog</code> for showing a small form to the user.</p> <p>On the ALertDialog are 2 buttons; namely "Submit" &amp; "Cancel".</p> <p>Now the fields (EditTexts) have setKeyListeners attached to them individually.</p> <p>The problem which I face is suppose the user doesn't fills in any field and directly clicks on <code>Submit</code> button then the dialog box closes automatically.</p> <p>Here's my Method which is called for creating/showing the Dialog Box:</p> <pre><code>Context ctx = this.getApplicationContext(); LinearLayout layoutCreateMerch = new LinearLayout(ctx); layoutCreateMerch.setOrientation(LinearLayout.VERTICAL); layoutCreateMerch.setVerticalScrollBarEnabled(true); final AlertDialog.Builder alert = new AlertDialog.Builder(Store.this); alert.setTitle("New Store"); final EditText stoName = new EditText(Store.this); final EditText stoDesc = new EditText(Store.this); InputFilter[] FilterMaxLen = new InputFilter[1]; FilterMaxLen[0] = new InputFilter.LengthFilter(25); stoName.setFilters(FilterMaxLen); stoName.setHint("Store's Name"); stoName.setKeyListener(DigitsKeyListener.getInstance("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,&amp;apos;1234567890 ")); stoName.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); layoutCreateMerch.addView(stoName); stoDesc.setFilters(FilterMaxLen); stoDesc.setHint("Store's Description"); stoDesc.setKeyListener(DigitsKeyListener.getInstance("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,&amp;apos;1234567890 ")); stoDesc.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); layoutCreateMerch.addView(stoDesc); ScrollView scroll = new ScrollView(ctx); scroll.setBackgroundColor(Color.TRANSPARENT); scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); scroll.addView(layoutCreateMerch); alert.setView(scroll); alert.setNeutralButton("Submit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (Name.getText().toString().equals("") || Desc.getText().toString().equals("")) { if(stoName.getText().toString().equals("")){ stoName.setHint("fill Store's Name"); stoName.setHintTextColor(Color.RED); } else{} if( stoDesc.getText().toString().equals("")){ stoDesc.setHint("fill Store's Description"); stoDesc.setHintTextColor(Color.RED); } else{} if.. .. .. } else { System.out.println("should not exit :| "); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); </code></pre> <p>Any advice is appreciated.. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload