我在多选模式下为上下文菜单注册了一个列表视图:
private void initListViewForContextMenu(){
log.d("FilesFragment", "initListViewForContextMenu()");
ListView listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { ...
问题是并非我的视图中的所有项目都应该是可选择的,只有那些显示特殊图标的项目应该可供选择。我不知道如何实现这一点,我定义了一个OnItemLongClickListener
:
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) {
Log.d("FilesFragment", "OnItemLongClickListener.onItemLongClick at pos " + position);
PfmDocument doc = (PfmDocument)adapter.getItemAtPosition(position);
if (doc.isOnBasket()){
Log.d("FilesFragment", "OnItemLongClickListener.onItemLongClick detected in basket");
ListView lv = (ListView) adapter;
lv.setItemChecked(position, false);
}
return false;
}
});
但是这个监听器永远不会被调用。
我也尝试OnLongClickListener
在适配器中设置行视图,但是即使上下文菜单关闭(不在选择模式下),执行此正常单击也会禁用。
if (doc.isOnBasket()){
rowView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return false; // do nothing, already in basket
}
});
// }