Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Onur Ozbek
PLUS
Onur Ozbek
Courses Plus Student 2,451 Points

setOnChildClickListener does not work

I'm trying to use Intent in my ExpandableListView.setOnChildClickListener to launch another activity but it doesn't work. I went through stackoverflow but the solutions did not relate to my problem. The following is my code:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //code omitted to make it shorter
        expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView expandableListView,
                                        View view,
                                        int groupPosition,
                                        int childPosition,
                                        long id) {
                activityStartIntent();
                return true;
            }
        });

    }

    public void activityStartIntent(){
        Intent intent = new Intent(MainActivity.this, AssignmentActivity.class);
        startActivity(intent);

And yes I did put the return type to true in isChildSelectable method:

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

I don't have any clickable or focusable attributes in my XML files. Despite all of this, I still cannot get my children onClick to work.

Thanks.