I had copied the code for expanded list view from somewhere on stack and it work properly, i was able to expand the list and click both parent and child, But when i added the check_box element to the layout the child view click does not work any more. Please help me with this, its very odd as i am just adding one check-box element.
// does not work with when check box element is there
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/expandedListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:paddingTop="10dp"
android:paddingBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="63dp"
android:layout_height="19dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="56dp"
android:layout_marginRight="56dp"
android:text="Available"
app:layout_constraintBottom_toBottomOf="@+id/expandedListItem"
app:layout_constraintEnd_toEndOf="@+id/expandedListItem"
app:layout_constraintTop_toTopOf="@+id/expandedListItem"
app:layout_constraintVertical_bias="0.0" />
<CheckBox
android:id="@+id/available"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:onClick="onCheckboxClicked"
android:text=""
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/expandedListItem"
app:layout_constraintHorizontal_bias="0.829"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
//Here is the activity part where click methods have been written.
expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
expandableListTitle.get(groupPosition) + " List Expanded.",
Toast.LENGTH_SHORT).show();
Log.d("Expanded1", "Expanded");
}
});
expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
expandableListTitle.get(groupPosition) + " List Collapsed.",
Toast.LENGTH_SHORT).show();
}
});
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Log.d("Child Clicked", "Child Clicked");
Toast.makeText(
getApplicationContext(),
expandableListTitle.get(groupPosition)
+ " -> "
+ expandableListDetail.get(`enter code here`
expandableListTitle.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT
).show();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("itemName", expandableListDetail.get(
expandableListTitle.get(groupPosition)).get(
childPosition) ));
params.add(new BasicNameValuePair("available", "N"));
JSONParser jParser = new JSONParser();
jParser.hitURL(url, params);
Log.d("Update Stock-1", "Update");
return false;
}
});
CLicking the child view item should have been working in both cases, But in presence of check-box click on child is not even being recognized, the method expandableListView.setOnChildClickListener is not even being called....
You need to add android:focusable="false"
for the CheckBox
<CheckBox
android:id="@+id/available"
android:focusable="false"
....
/>