I want to show custom action bar when checkbox checked in listview. I wrote the one xml file type of menu like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://ift.tt/nIICcg" >
<item
android:id="@+id/delete"
android:title="actionbar"
android:icon="@drawable/recycle"/>
</menu>
I use for custom listview this 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 this class for 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 I check the checkboxes in listview , action bar don't changed . Please advice.
Aucun commentaire:
Enregistrer un commentaire