我有一个带有上下文动作模式的片段。上下文动作模式运行良好。 ActionMode.Callback有一个onActionItemClicked方法。我想在我的班级中覆盖这个方法。下面是我试过的代码。我的类中的覆盖方法没有被调用。
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方法没有被调用。如何解决这个问题。
答案 0 :(得分:1)
尝试以下方法:
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;
}
});
}
}