android - disabled listitems in alertdialog does not show up as grayed out items -
this scenario.
i have activity in have show dialog box (which listview wit 2 options optiona , optionb). listview used in single choice mode. option disabled(the user not allowed select option a)
these code fragments
private void createdialog() { boolean disableoptiona = false; ... alertdialog.builder builder = new alertdialog.builder(this); builder.settitle(getstring(r.string.codec_title)); listview modelist = new listview(this); final arrayadapter<charsequence> modeadapter = custommenuadapter.createfromresource(this, r.array.codec_decoder, android.r.layout.simple_list_item_single_choice, disableoptiona); modelist.setchoicemode(listview.choice_mode_single); modelist.setadapter(modeadapter); builder.setview(modelist); final dialog dialog = builder.create(); ... } the codec_decoder array contains 2 options optiona , optionb. code custommenuadapter follows.
public class custommenuadapter extends arrayadapter<charsequence> { boolean disableoptiona = true; private custommenuadapter(context context, int textviewresid, charsequence[] strings, boolean disableoptiona) { super(context, textviewresid, strings); this.disableoptiona = disableoptiona; } public static custommenuadapter createfromresource(context context, int textarrayresid, int textviewresid, boolean disableoptiona) { resources resources = context.getresources(); charsequence[] strings = resources.gettextarray(textarrayresid); return new custommenuadapter(context, textviewresid, strings, disableoptiona); } @override public view getview(int position, view convertview, viewgroup parent) { view view = super.getview(position, convertview, parent); view.setenabled(isenabled(position)); return view; } @override public boolean areallitemsenabled() { return false; } @override public boolean isenabled(int position) { if (position == 0) { if (disableoptiona) { return false; } } return true; } } now works well, when optiona disabled, acts disabled looks enabled, not grayed out. ideas?
all need replace following code:
@override public boolean isenabled(int position) { if (position == 0) { if (disableoptiona) { return false; } } return true; } with in case want disable item on position 1:
@override public boolean isenabled(int position) { if (position == 1) return true; return false; }
Comments
Post a Comment