我有一个 BaseExpandableListAdapter 看起来像这样:
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final ContentViewHolder contentViewHolder;
View view = convertView;
final Book book = getChild(groupPosition, childPosition);
if (view == null) {
LayoutInflater inflater = context.getLayoutInflater();
view = inflater.inflate(R.layout.item_book_row, null);
contentViewHolder = new ContentViewHolder();
contentViewHolder.tvName = (TextView) view.findViewById(R.id.tvName);
contentViewHolder.chkSelected = (CheckBox) view.findViewById(R.id.chkSelected);
view.setTag(contentViewHolder);
}else{
contentViewHolder = (ContentViewHolder) view.getTag();
}
contentViewHolder.tvName.setText(book.getTitle());
contentViewHolder.chkSelected.setChecked(checkStates[groupPosition][childPosition]);
contentViewHolder.chkSelected.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
book.setSelected(contentViewHolder.chkSelected.isChecked());
checkStates[groupPosition][childPosition] = contentViewHolder.chkSelected.isChecked();
Ln.d("check on header %d row %d", groupPosition, childPosition);
}
});
return view;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
Ln.d("Child selected "+groupPosition+" : "+childPosition);
return true;
}
与子布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<!-- Row data -->
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
<CheckBox
android:id="@+id/chkSelected"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="@dimen/item_vertical_margin"
android:layout_marginRight="@dimen/item_vertical_margin" />
</RelativeLayout>
这是片段视图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ExpandableListView
android:id="@+id/lstCatBook"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:groupIndicator="@null">
</ExpandableListView>
</LinearLayout>
然后我setOnChildClickListener
在我的片段上注册。
lstCatBook.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Log.d("Click on group " +groupPosition +" child " + childPosition);
return false;
}
});
当我单击行项目或复选框时,一切都很好。但问题是当我将列表视图滚动到底部时,我无法再次单击行项目(onChildClick
未触发),而复选框可以工作
我对这个问题没有任何想法。我已经搜索并尝试了很多方法,例如: set check box focusable = false
,descendantFocusability=blocksDescendants
但没有任何帮助。
我哪里错了?任何帮助,将不胜感激。