diegodobelo / AndroidExpandingViewLibrary

This is a library to help creating expanding views with animation in Android
942 stars 120 forks source link

OnCLickListener ?? #6

Open lovingnirav opened 7 years ago

lovingnirav commented 7 years ago

How to add OnclickListener to subitem ?

diegodobelo commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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);