gpt4 book ai didi

java - 如何在android中覆盖ActionMode的onActionItemClicked

转载 作者:行者123 更新时间:2023-11-30 01:24:47 26 4
gpt4 key购买 nike

我有一个带有上下文操作模式的 fragment 。上下文操作模式运行良好。 ActionMode.Callback 有一个 onActionItemClicked 方法。我想在我的类(class)中重写这个方法。下面是我试过的代码。我的类中的覆盖方法没有被调用。

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;
}

});
}
}

关于java - 如何在android中覆盖ActionMode的onActionItemClicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36541186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com