Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnCLickListener ?? #6

Open
lovingnirav opened this issue Jan 2, 2017 · 4 comments
Open

OnCLickListener ?? #6

lovingnirav opened this issue Jan 2, 2017 · 4 comments

Comments

@lovingnirav
Copy link

How to add OnclickListener to subitem ?

@diegodobelo
Copy link
Owner

Hi @lovingnirav , you can get the subitem view by calling the method getSubItemView of ExpandingItem object. Then, you can set the click listener on that view.
Please check the example code here: https://github.com/diegodobelo/AndroidExpandingViewLibrary/blob/master/example/src/main/java/com/diegodobelo/expandinganimlib/MainActivity.java#L67

You just have to do something like:

final View view = item.getSubItemView(i);
view.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // perform action
    }
});

@lovingnirav
Copy link
Author

On line 41

addItem("John", new String[]{"House", "Boat", "Candy", "Collection", "Sport", "Ball", "Head"}, R.color.pink, R.drawable.ic_ghost);

How would you set different action for different subitem

Example i want to start Activity1 on House click and Activity2 to open on Boat click Activity 3 to open on Candy click and so on..

@diegodobelo
Copy link
Owner

On line 96 you may replace the code by:

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (subTitle.equals("House")) {
                    startActivity(new Intent(MainActivity.this, HouseActivity.class));
                } else if (subTitle.equals("Boat")) {
                    startActivity(new Intent(MainActivity.this, BoatActivity.class));
                }
                ...
            }
        });

@lovingnirav
Copy link
Author

Thanks it worked ....
One more question what if their are two same subTitle in different Title, how do i set different actions ??
Example

    addItem("John", new String[]{"House", "Boat"}, R.color.pink, R.drawable.ic_ghost);
    addItem("Mary", new String[]{"House", "Boat"}, R.color.blue, R.drawable.ic_ghost);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants