daimajia / AndroidSwipeLayout

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

setSwipeListener instead of addSwipeListener #231

Open danvass opened 9 years ago

danvass commented 9 years ago

Is there a way to setSwipeListener instead of addSwipeListener? I'm trying to use it in an ArrayAdapter but I need to set the swipe listener in getView instead of adding new ones.

Thanks, Daniel

danvass commented 9 years ago

My current solution is keeping a track of all SwipeListeners and removing them and adding the one I need.

spidfire commented 8 years ago

I did it this way (in kotlin code) but it would be great if someone could either implement the setSwipeListener or the clearAllSwipeListeners


import android.content.Context
import android.util.AttributeSet
import com.daimajia.swipe.SwipeLayout

class CustomSwipeLayout(context: Context, attr: AttributeSet) : SwipeLayout(context, attr){

    var prev:SwipeListener? = null
    fun setSwipeListener(s: SwipeListener){
        if(prev != null){
            println("self broadcast duplicate listenenr")
            removeSwipeListener(prev)
            prev = null
        }
        addSwipeListener(s)
        prev = s
    }
}