我在每一行都有一个带有 OnClickListeners 的 ListView:
来自适配器的代码 (BaseAdpater)
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final Lecture lecture = getItem(position);
View rowView = convertView;
if (rowView == null) {
rowView = mLayoutInflater.inflate(R.layout.notes_lecture_list, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.id = (TextView) rowView.findViewById(R.id.tv_lecture_id);
viewHolder.name = (TextView) rowView.findViewById(R.id.tv_lecture_name);
viewHolder.row = (LinearLayout) rowView.findViewById(R.id.ll_lecture_notes);
viewHolder.arrow = (ImageView) rowView.findViewById(R.id.iv_notes_menu_arrow);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
holder.row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
select(lecture);
}
});
}
我想用 CAB 实现多行删除:
private void prepareAdapter() {
mAdapter = new MyListAdapter(this);
mMultiChoiceListener = new MyMultiChoiceModeListener(this, mAdapter);
mMyListView.setAdapter(mAdapter);
mMyListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
mMyListView.setMultiChoiceModeListener(mMultiChoiceListener);
}
问题是在getView方法中multipleChoiceListener(onLongClick)不能和OnClickListener一起工作,CAB不显示,如果我取下OnClickListener,multipleChoiceListener工作正常,CAB显示正常。
你有什么想法?我是否应该尝试另一种方式,例如实现 OnLongClick 来调用 CAB?我知道这是可能的,因为 Gmail 做到了。