Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.