Search code examples
androidandroid-listview

Multiple Delete - MultiChoiceListener don't work with OnClickList


I have one ListView with OnClickListeners in each row:

code from the adapter (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);
        }
    });  
}

I want to implement multiple row delete with 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);
}

The problem is that the multipleChoiceListener (onLongClick) don't work with OnClickListener in the getView Method, CAB is not displayed, if I take off the OnClickListener the multipleChoiceListener works fine, CAB is displayed normally.

Do you have any ideas? Should I try another way like implement OnLongClick to call the CAB? I know that it is possible because Gmail does it.


Solution

  • Found the solution.

    Use OnItemClickListener on the listView works fine.