ExpandableListView.setOnClickListener not working properly

时间:2015-09-01 21:41:09

标签: java android expandablelistview expandablelistadapter

My set-up


I have a custom ExpandableListAdapter (that extends BaseExpandableListAdapter), inside of which I am overriding the isChildSelectable method and returning true:

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

Inside the overrided onCreateView method inside my Fragment class I am setting an onChildClickListener this way:

expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
    @Override
       public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
         try {
           DownloadThisPatientInfo.downloadThisPatientInfo(...);
           return true;
         } catch (NullPointerException e) {
           return false;
         }
       }
});

My problem


The code inside onChildClick method is not being called.

What I have tried to detect the problem


First of all: the Logcat shows no errors, and the program just continues its execution after clicking a child, as if I didn't click it. No errors, no warnings, nothing.

I tried setting a breakpoint then going into debugging mode. Breakpoint in line:

try {

This breakpoint isn't being triggered after a child click. Just in case, I tried making a Log.d(str, str) call just before the try block:

expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
       Log.d("TESTING", "### Child Clicked.");
       try { ... }
       catch ( ... ) { ... }
});

Nothing appears in the Log.

Obviously the code inside onChildClick isn't being called. I am sure it must be something quite obvious. Why is this happening? I'll update with more code if it's necessary.

1 个答案:

答案 0 :(得分:0)

解决。请考虑将android:descendantFocusability="blocksDescendants"添加到商品的父级LinearLayout。