ListView中适用CheckBox导致OnItemClicklistener点击失效怎么办呢?
原因时CheckBox的onfucus要优先于listview,只要设置CheckBox的android:focusable="false"就行了
至于CheckBox的check状态,可以在Adapter的getView中自行判断
样本:
package com.fanshuo.android.bestnotes.app.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import com.fanshuo.android.bestnotes.R;
import com.fanshuo.android.bestnotes.app.model.BestNotesTextNoteModel;
public class BestNotesTextNoteAdapter extends ArrayAdapter<BestNotesTextNoteModel>{
public BestNotesTextNoteAdapter(Context context) {
super(context, 0);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.bestnotes_item_mainlist, null);
}
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.checkbox);
checkBox.setChecked(((ListView)parent).isItemChecked(position));
TextView title = (TextView) convertView.findViewById(R.id.textview_title);
TextView time = (TextView) convertView.findViewById(R.id.textview_time);
TextView content = (TextView) convertView.findViewById(R.id.textview_content);
title.setText(getItem(position).getTitle());
time.setText(getItem(position).getCreateTime()+"");
content.setText(getItem(position).getContent());
return convertView;
}
}