Reputation: 10203
I have an BaseExpandableListAdapter look like this:
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;
}
with the child layout:
<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>
And here is the fragment view:
<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>
Then I register setOnChildClickListener
on my fragment.
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;
}
});
Everything is fine when I click on row item or checkbox. But the problem is when I scroll listview to the bottom, I can't click on row item again (the onChildClick
not fired ) while check box can work
I have no ideas with this issue.
I have searched and tried many ways like: set check box focusable = false
, descendantFocusability=blocksDescendants
but nothing can help.
Where am I wrong? any help would be appreciated.
Upvotes: 1
Views: 945
Reputation: 10203
Finally I figure out the problem: cause I use set Expand for all group if listview. I don't know why setOnChildClickListener
doesn't work in this case. But I can work around by catch the click event on convert view from getChildView and then notify for the main view.
Something like that:
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
//load data
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// notify for main view by using another listener
}
});
return converview;
}
Upvotes: 2