我想知道为recyclerView项ViewHolder定义滑动手势侦听器的正确方法是什么。这是做什么的:
interface StockItemViewClickListener {
fun onItemClick(stock: Stock)
fun onItemLongClick(stock: Stock)
fun onGestureListener(stock: Stock)
}
this
class MainActivity : AppCompatActivity(), StockItemViewClickListener {
// some code here ...
}
class StockViewHolder(
private val view: View,
private val itemClickListener: StockItemViewClickListener
) : RecyclerView.ViewHolder(view) {
view.setOnClickListener {
stock?.let {
itemClickListener.onItemClick(it)
}
}
view.setOnLongClickListener {
stock?.let {
itemClickListener.onItemLongClick(stock)
}
true
}
// some other code
}
定义onItemClick和onItemLongClick非常容易,但是我不知道如何处理ViewHolder中的手势。我已阅读本文https://developer.android.com/training/gestures/detector.html,但不确定如何正确地将其应用于我的代码。任何帮助将不胜感激!伪代码就足够了!