[英]How to select an item from GridView by long pressing ,on so i need to open the Contextual ActionBar menu with Item Selected?
我设计了一个带有网格视图的视图传呼器,其中包含Icon的列表。我需要通过选择一个Icon来显示上下文操作栏,也需要选择该图标。请问您给我一个建议吗?
我还在使用函数OnItemLongClickListener()
帮我解决上述问题吗?
用这个
mMultiChoiceModeListener = new MultiChoiceModeListener() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
mode = null;
mAdapter.clearSelection();
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.setTitle("Options");
mode.getMenuInflater().inflate(R.menu.action_mode, menu); // inflate your menu for the contextual action bar here
return true;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
// handle the click of the buttons of the contextual action bar here as a normal menu
}
return true;
}
@Override
public void onItemCheckedStateChanged(ActionMode mode,
int position, long id, boolean checked) {
}
};
mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
mGrid.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
arg1.setSelected(true);
return true;
}
});
mGrid.setMultiChoiceModeListener(mMultiChoiceModeListener);
并为此使用普通菜单!
我在这里看到一个错误,有时有效,有时无效。 改变这个
mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
mGrid.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
arg1.setSelected(true);
return true;
}
});
对此:
mGrid.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
arg1.setSelected(true);
return true;
}
});
然后在on create上输入以下内容:
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.