android - Why don't active contextual action bar when check the checkbox on the listview? -
i want show custom action bar when checkbox checked in listview. wrote 1 xml file type of menu this:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/delete" android:title="actionbar" android:icon="@drawable/recycle"/> </menu>
i use custom listview codes:
private class adapter_collection extends arrayadapter<string> { public adapter_collection(context context, int resource, int textviewresourceid, string[] name_collection_tbl_collection) { super(context, resource, textviewresourceid, name_collection_tbl_collection); } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service); view row = inflater.inflate(r.layout.listview_items, parent, false); textview txt_item_list_collection = (textview)row.findviewbyid(r.id.textview_item_listview); checkbox checkbox=(checkbox)row.findviewbyid(r.id.checkbox_item_listview); checkbox.settag(position); checkbox.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked ) { if (mactionmode!=null) { myactionmodecallback callback = new myactionmodecallback(); mactionmode = startactionmode(callback); } //toast.maketext(getapplicationcontext(), buttonview.gettag().tostring() , toast.length_short).show(); } }); txt_item_list_collection.settext(name_collection_tbl_collection[position]); return row; }
}
i add class use contextual action bar :
private class myactionmodecallback implements actionmode.callback { @override public boolean onactionitemclicked(actionmode mode, menuitem item) { // todo auto-generated method stub return false; } @override public boolean oncreateactionmode(actionmode mode, menu menu) { mode.getmenuinflater().inflate(r.menu.actionbar_menu, menu); return true; } @override public void ondestroyactionmode(actionmode mode) { mactionmode = null; } @override public boolean onprepareactionmode(actionmode mode, menu menu) { // todo auto-generated method stub return false; } }
now when check checkboxes in listview , action bar don't changed . please advice.
this problem solved change :
checkbox.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked ) { myactionmodecallback callback = new myactionmodecallback(); mactionmode = startactionmode(callback); //toast.maketext(getapplicationcontext(), buttonview.gettag().tostring() , toast.length_short).show(); } });
Comments
Post a Comment