android - Contextual Action Bar and Checkbox problems -
so got far this, please keep in mind listview dynamic called api.
- an adapter listview.
- contextual actionbar implementation.
what needed.
- for contextual actionbar , checkbox items sync (like if icons unchecked, action bar destroyed)
what tried:
@override public view getview(int position, view convertview, viewgroup parent) { // todo auto-generated method stub viewholder vh; if(convertview == null){ vh = new viewholder(); convertview = minflater.inflate(r.layout.projectlist_frame, null); vh.projecttitle = (textview)convertview.findviewbyid(r.id.projecttitle); vh.projectsector = (textview)convertview.findviewbyid(r.id.projectsector); vh.cb = (checkbox)convertview.findviewbyid(r.id.checkbox1); convertview.settag(vh); } else{ vh = (viewholder)convertview.gettag(); } vh.projecttitle.settext(mdata.get(position).get("title").tostring()); vh.projectsector.settext(mdata.get(position).get("sector").tostring()); vh.cb.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { // todo auto-generated method stub if(ischecked){ if(mmode==null){ mmode = startactionmode(mactioncallback); } } else{ if(mmode!=null){ mmode.finish(); } } } }); return convertview; } @override public int getviewtypecount() { // todo auto-generated method stub return super.getviewtypecount(); } class viewholder{ textview projecttitle, projectsector; checkbox cb; } }
for in contextuals actionbar
private actionmode.callback mactioncallback = new actionmode.callback() { @override public boolean onprepareactionmode(actionmode mode, menu menu) { // todo auto-generated method stub return false; } @override public void ondestroyactionmode(actionmode mode) { // todo auto-generated method stub (int = 0; < list.getadapter().getcount(); i++) list.setitemchecked(i, false); if (mode == mmode) { mmode = null; } } @override public boolean oncreateactionmode(actionmode mode, menu menu) { // todo auto-generated method stub mode.settitle("options"); mode.getmenuinflater().inflate(r.menu.contextual_menu_add_project, menu); return true; } @override public boolean onactionitemclicked(actionmode mode, menuitem item) { // todo auto-generated method stub long[] selected = list.getcheckeditemids(); if (selected.length > 0) { (long id: selected) { // selected item } } mode.finish(); return false; } };
can please me track oncheck events , coordinate actions contextual actionbar.
Comments
Post a Comment