android - Custom array adapter doesn't work in DialogFragment -
i want populate list view custom array adapter, looks getview() never called. below code, part creates dialog:
@override public dialog oncreatedialog(bundle savedinstancestate) { // use builder class convenient dialog construction alertdialog.builder builder = new alertdialog.builder(getactivity()); builder.setpositivebutton("delete", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { //do deletion } }) .setnegativebutton(r.string.cancel, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { // user cancelled dialog } }); builder.settitle("dialog title").setview(getcustomview()); return builder.create(); }
this part creates view, commented on works, doesn't
public view getcustomview(){ layoutinflater inflater = (layoutinflater) getactivity().getsystemservice(context.layout_inflater_service); view view = inflater.inflate(r.layout.dialog_delete_option, null); listview listview = (listview) view.findviewbyid(r.id.listdeloptions); /*this default array adapter, works */ list<string> list = new arraylist<string>(); list.add("del one"); list.add("del all"); arrayadapter<string> defaultadapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_list_item_single_choice, list); /*this custom adapter, not working */ madapter = new deleteadapter(getactivity(),0); //last int not used since //know layout inflate //not working //listview.setadapter(madapter); //madapter.notifydatasetchanged(); //working listview.setadapter(defaultadapter); return view; }
this custom array adapter, getview
relevant, post here whole class in case.
public static class deleteadapter extends arrayadapter{ private final int mlayoutid; private int mcheckpos; context mcontext; string [] mbuttondescription; public deleteadapter(context context, int resource) { super(context, resource); mlayoutid= r.layout.delete_list_item_view; mcontext = context; mcheckpos = 0; mbuttondescription = new string[3]; mbuttondescription[0] = context.getstring(r.string.del_only_this_event); mbuttondescription[1] = context.getstring(r.string.del_this_and_future_events); mbuttondescription[2] = context.getstring(r.string.del_all_events); } @override public view getview(int position, view convertview, viewgroup parent) { view view =convertview; if (view==null){ view = view.inflate(mcontext,mlayoutid, null); } radiobutton button = (radiobutton) view.findviewbyid(r.id.rddeloption); button.settag(new integer(position)); button.setoncheckedchangelistener(checkedchangelistener); if (position== mcheckpos) button.setchecked(true); else button.setchecked(false); button.settext(mbuttondescription[position]); return view; } compoundbutton.oncheckedchangelistener checkedchangelistener = new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked){ mcheckpos = (integer) buttonview.gettag();//tag position } } }; public int getselecteditem(){ return mcheckpos; } }
what's wrong deleteadapter? thanks.
Comments
Post a Comment