Available (Enable) status of buttons in Android settings Alertdialog

Source: Internet
Author: User

Pop up a dialog box to save the file, to control the input content limit, and the Save button is unavailable when the content is empty. Directly on the code:

Layoutinflater Minflater =Layoutinflater.from (mactivity); View Saveview= Minflater.inflate (R.layout.alert_dlg_save,NULL);//set the EditText property of the input file nameFinalEditText filename =(EditText) Saveview.findviewbyid (r.id.dlg_save_input_filename); Filename.setfilters (NewInputfilter[] {NewInputfilter.lengthfilter (255),Newspecialfilter ()}); Filename.settext (Mstrasname); TextView DefaultPath=(TextView) Saveview.findviewbyid (R.id.dlg_save_default_path);d efaultpath.settext (Datastruct.gfloder+ "/"); Alertdialog.builder Builder=NewAlertdialog.builder (mactivity, alertdialog.theme_holo_light); Builder.settitle (R.string.maker_menu_save); Builder.seticon (R.drawable.icon_small); Builder.setview (Saveview); Builder.setpositivebutton (R.string.maker_menu _save,NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {        //TODO auto-generated Method StubString name =Filename.gettext (). toString (). Trim (); Name+ = ". ASTP"; String Namepath= Datastruct.gfloder + "/" +name; if(SaveFile (Namepath)) {Mstrsavedpath=Namepath; Mbtnsave.setenabled (false); } Else{toastfailedsave (); }}); Builder.setnegativebutton (R.string.btn_cancel,NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {        //TODO auto-generated Method Stub}});D Ialog Dialog=builder.create ();d ialog.show ();//get the Positivebutton focus hereFinalButton BTN =((Alertdialog) dialog). Getbutton (dialoginterface.button_positive);//the input cannot be emptyFilename.addtextchangedlistener (NewTextwatcher () {@Override Public voidOnTextChanged (Charsequence S,intStartintBefore,intcount) {        //TODO auto-generated Method Stub} @Override Public voidBeforetextchanged (Charsequence S,intStartintCountintAfter ) {        //TODO auto-generated Method Stub} @Override Public voidaftertextchanged (Editable s) {//TODO auto-generated Method StubString name =s.tostring (). Trim (); if(Name.isempty ()) btn.setenabled (false); Elsebtn.setenabled (true); }});

Available (Enable) status of buttons in Android settings Alertdialog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.