android - Enable and disable dialog depending on correct input? -
this popup button needs disabled if user clicks submit without entering input first:
new alertdialog.builder(getactivity()) .setview(view) .setpositivebutton(android.r.string.ok, new dialoginterface.onclicklistener() { @override public void onclick(final dialoginterface dialog, final int which) { edittext nameedittext = (edittext) view .findviewbyid( r.id.save_search_dialog_name); posttobus(new savesearchevent( nameedittext.gettext().tostring(), search)); posttobus(new googleanalyticevent( ga.category_search_control, ga.event_search_save_search)); dialog.dismiss(); } //check see if dialog empty private boolean isempty(edittext ettext) { return ettext.gettext().tostring().trim().length() == 0; } }
i trying create method check ensure popup dialog cannot blank. have attempted method isempty , unsure how use it, or maybe isn't correct approach? assistance appreciated.
can provide context please? have button should enabled/disabled? in case case suggest using this:
edittext edittext = (edittext)findviewbyid(r.id.your_edit_text_id); edittext.addtextchangedlistener(new textwatcher() { @override public void aftertextchanged(editable s) { } @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { if(textutils.isempty(s)) { // check whatever want // disable button or } else { // enable } } });
Comments
Post a Comment