rey5137 / material

A library to bring fully animated Material Design components to pre-Lolipop Android.

Home Page:http://rey5137.com/material/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to implement ripple on ListView items

andrewpros opened this issue · comments

The title say it all, and please don't show mi this https://github.com/rey5137/material/wiki/Button i know about the documentation, but the ripplemanger doesn't work with OnItemClickListener, nor i have the knowledge to do it myself, i just need a working solution.

I have even made a custom linearlayout with ripple, works, but clicks stopped working, cuz it is onclick not itemclick, when i realised that it needs to be implemented in the listview or maybe adapterview directly.

Was trying to make a custom rippelmanager or ripplelistview, but for now it is beyond my android skills, i need help.

@rey5137 Any help?

You cannot use OnItemClickListener of list view has item with ripple effect because RippleDrawable will steal touch events. Instead of using OnItemClickListener , you can set View.OnClickListener directly on item view in getView() method of adapter.

Btw, I think you should switch to RecyclerView because it more flexible than ListView.

@rey5137

Isn't there any workaround, my adapters don't know anything about hosting fragment and it should stay that way, but my OnItemClickListener is set in those fragments with access to some data in this fragment instance, i can't move it to adapter, the app is near ready, more than 15 fragments, this should be the last task, fine tuning the visuals.

This is for me a no go, too many changes, but i still will need a custom root layout in listview item right?

Have seen libraries that make it simpler, maybe i will try to make some workaround for everyone, based how the layout wrappers work in others libs.

I will update how it goes asap.

Here is an example how to handle item view click event manually:

class YourAdapter extends BaseAdapter{

    private AdapterView.OnItemClickListener mOnItemClickListener;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = ...;

        v.setTag(position);
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = (Integer)v.getTag();
                mOnItemClickListener.onItemClick((AdapterView)v.getParent(), v, position, getItemId(position));
            }
        });

        return v;
    }
}

You can create a custom viewgroup that support ripple effect, or you can just add a transparent ripple button on top of your item view and handle click event of button.

And If you use RecyclerView, it also require you have to handle item click event manually.

I know how to make the click working, but i don't want to change it, against my app architecture and too many changes in whole app.

Couldn't make it work myself in a custom way, so for now i used https://github.com/balysv/material-ripple

I wanted to use the button but it has also strange error, when you use it without image drawable nine patch then the ripple effect has inside corner artifacts even if padding set to 0.

how to solve it?