daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

How can i make SwipeLayout Click to Open #441

Open caiovitord opened 7 years ago

caiovitord commented 7 years ago

How can i do the behavior just like the setClickToClose(boolean) but to open de layout ?

joaolisboa commented 7 years ago

You can use the code from the demo in ListViewExample:

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ((SwipeLayout)(mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true);
    }

});

You should also be able to do inside the adapter, unlike the demo, using the same method, setOnClickListener and calling open() on SwipeLayout.

comm1x commented 6 years ago

@joaolisboa You can't, because SwipeLayout is intercepting any touches, so click is not trigger.

joaolisboa commented 6 years ago

Maybe it's been a while and things have changed but that code was literal copy/paste from a project of mine, only changed variables names. Unless you mean doing it within the adapter as I mentioned at the bottom, which I don't remember whether I tested or not.

Bludyvenom commented 6 years ago

You can do it using the SurfaceView onClickListener(). Place the below onClickListener in the adapter class.

viewHolder.swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewHolder.swipeLayout.open(true);
            }
        });

Above onClickListener() works great even as an onClick for any item in the ListView/RecyclerView and unlike the onItemClickListener(), this is not called multiple times even when just swiping. I'm using this.