我想选择多个项目并使用操作栏进行操作。我尝试了以下代码,但它无法正常工作
listView = (ListView) findViewById(R.id.conversationList);
((ConversationsAdapter) conversationsAdapter).updateConversations(conversationsList);
listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
choiceModeListener = new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {
Toast.makeText(context,listView.getCheckedItemCount() ,Toast.LENGTH_SHORT).show();
}
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
MenuInflater menuInflater = actionMode.getMenuInflater();
menuInflater.inflate(R.menu.contextual_menu,menu);
return false;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
}
};
listView.setMultiChoiceModeListener(choiceModeListener);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Conversation item = (Conversation) conversationsAdapter.getItem(position);
startChat(item, false);
}
});
不知道为什么,MultiChoiceModeListener
永远不会打电话。问题是什么? OnItemClickListener
工作得非常好。