我有一个上下文操作模式片段。上下文操作模式运行良好。 ActionMode.Callback具有onActionItemClicked方法。我想在课堂上重写此方法。下面是我尝试过的代码。不调用类中的override方法。
public class HouseHoldMembersFragment extends ActionBarCallBack {
ActionMode mMode;
public HouseHoldMembersFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_house_hold_members, container, false);
ExpandList = (ExpandableListView) view.findViewById(R.id.expandable_list_view);
ExpandList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
mMode = view.startActionMode(new ActionBarCallBack());
return true;
}
return false;
}
});
return view;
}
这是实现类
public class ActionBarCallBack extends Fragment implements ActionMode.Callback {
ActionMode mMode;
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.getMenuInflater().inflate(com.deerwalk.androidcommon.R.menu.context_action_menu, menu);
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mMode = null;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.setTitle("Action");
return false;
}
}
我想将ActionMode设为通用并覆盖onActionItemClicked方法。到目前为止,我已经尝试过,但是没有调用我的类onActionItemClicked方法。如何解决这个问题。
最佳答案
请尝试以下操作:
ExpandList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
{
@Override
public boolean onItemLongClick (AdapterView < ? > parent, View view,int position, long id){
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.getMenuInflater().inflate(com.deerwalk.androidcommon.R.menu.context_action_menu, menu);
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mMode = null;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.setTitle("Action");
return false;
}
});
}
}