listview - Android O Beta Preview 3 - Lists and Adapters issues? -
i'm running latest developer preview of android o , i'm seeing following behaviours:
i have various lists inside dialog fragments use custom adapters extend baseadapter. these no longer selectable on android o.
i have other lists inside fragments (not dialog fragments) which
use custom adapters extend arrayadapter<>. these work fine on android o.when try , change dialog fragment list adapters extend arrayadapter<>, lists still not selectable.
below sample wrote recreate problem i'm experiencing inside app. have activity creates dialog fragment has list inside. list adapter extends baseadapter. list unresponsive , onitemclicklistener never fired.
this pattern worked in app until android o.
has else experienced problem? i've had hunt around documentation , doesn't mention changes around adapters/lists.
thanks in advance help!
activity:
public class mainactivity extends appcompatactivity { list<string> wafilms = new arraylist<>(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); setuplist(); button button = (button) findviewbyid(r.id.launchbutton); button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { listdialogfragment ldf =listdialogfragment.getinstance(wafilms); ldf.show(getfragmentmanager(), "listdialogfragment."); } }); } private void setuplist() { wafilms.add(0, "bottlerocket"); wafilms.add(1, "rushmore"); wafilms.add(2, "the royal tenenbaums"); wafilms.add(3, "the life aquatic"); wafilms.add(4, "the darjeeling limited"); wafilms.add(5, "fantastic mr fox"); wafilms.add(6, "moonrise kingdom"); wafilms.add(7, "the grand budapest hotel"); } }
dialog fragment:
public class listdialogfragment extends dialogfragment { list<string> wafilms = new arraylist<>(); public static listdialogfragment getinstance(list<string> answeroptions) { listdialogfragment f = new listdialogfragment(); f.wafilms = answeroptions; return f; } @nonnull @override public dialog oncreatedialog(bundle savedinstancestate) { listview list = (listview) view.inflate(getactivity(), r.layout.dialog_fragment_list, null); list.setadapter(new simpleadapter(2, wafilms, getactivity())); list.setonitemclicklistener(onclicklistener); alertdialog.builder builder = new alertdialog.builder(getactivity()); builder.settitle("please pick film."); builder.setview(list); dialog d = builder.create(); d.setcanceledontouchoutside(false); return d; } adapterview.onitemclicklistener onclicklistener = new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> adapterview, view view, int position, long l) { string chosenoption = wafilms.get(position); toast.maketext(getactivity(), "your chosen film is: " + chosenoption, toast.length_short).show(); } }; }
adapter:
public class simpleadapter extends baseadapter { private list<string> items; private context context; private int selection; public simpleadapter(int selection, list<string> items, context context) { super(); this.items = items; this.selection = selection; this.context = context; } @override public int getcount() { return items.size(); } @override public object getitem(int i) { return items.get(i); } @override public long getitemid(int i) { return i; } @override public view getview(int position, view convertview, viewgroup parent) { if (convertview == null) convertview = ((layoutinflater) context.getsystemservice(context.layout_inflater_service)).inflate(r.layout.form_dialog_list_item, null); textview text = convertview.findviewbyid(r.id.listtextview); imageview star = convertview.findviewbyid(r.id.listselectionicon); star.setvisibility(position == selection ? view.visible : view.gone); text.settext(items.get(position)); return convertview; } public list<string> getitems() { return items; } }
Comments
Post a Comment