AndroidSwipeLayout icon indicating copy to clipboard operation
AndroidSwipeLayout copied to clipboard

How can i make SwipeLayout Click to Open

Open caiovitord opened this issue 8 years ago • 4 comments

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

caiovitord avatar Jun 07 '17 19:06 caiovitord

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.

joaolisboa avatar Jun 19 '17 23:06 joaolisboa

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

comm1x avatar Feb 28 '18 23:02 comm1x

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.

joaolisboa avatar Feb 28 '18 23:02 joaolisboa

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.

Bludyvenom avatar May 07 '18 04:05 Bludyvenom