bounty将在6小时后到期。回答此问题可获得+50声望奖励。MARSH正在寻找来自可靠来源的答案:我想要一个项目的双交换。
class DragAndDropAdapterForShoppingList(
val adapter: ShoppingListAdapter,
swipeDirs: Int,
private val onSwapToDelete: SingleLiveData<ShoppingListContentWidget.CallToAction>
) :
ItemTouchHelper.SimpleCallback(0, swipeDirs) {
private var listAdapter = adapter
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder,
): Boolean {
return true
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
Timber.log(1, "")
onSwapToDelete.value = ShoppingListContentWidget.CallToAction.SwappedToDelete(
(
adapter.items[
viewHolder
.adapterPosition
] as ShoppingListUIItem
)
)
listAdapter.deleteItem(viewHolder.adapterPosition)
}
override fun onChildDraw(
c: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean,
) {
val foregroundView = getForegroundView(viewHolder)
getDefaultUIUtil().onDraw(
c,
recyclerView,
foregroundView,
dX,
dY,
actionState,
isCurrentlyActive
)
}
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
val foregroundView = getForegroundView(viewHolder)
getDefaultUIUtil().clearView(foregroundView)
}
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
if (viewHolder != null) {
val foregroundView = getForegroundView(viewHolder)
getDefaultUIUtil().onSelected(foregroundView)
}
}
override fun onChildDrawOver(
c: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder?,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean,
) {
val foregroundView = getForegroundView(viewHolder)
getDefaultUIUtil().onDrawOver(
c,
recyclerView,
foregroundView,
dX,
dY,
actionState,
isCurrentlyActive
)
}
override fun getSwipeDirs(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
return if ((adapter.items[viewHolder.adapterPosition] is ShoppingListUIItem.SpecificItem)) {
super.getSwipeDirs(recyclerView, viewHolder)
} else {
if ((adapter.items[viewHolder.adapterPosition] as ShoppingListUIItem.GenericItem).name?.isEmpty() == true ||
(adapter.items[viewHolder.adapterPosition] as ShoppingListUIItem.GenericItem).name == null
) {
0
} else {
super.getSwipeDirs(recyclerView, viewHolder)
}
}
}
private fun getForegroundView(viewHolder: RecyclerView.ViewHolder?): ConstraintLayout? {
return (viewHolder as? ShoppingListGenericItemViewHolder)?.genericItemViewFrontView
?: (viewHolder as? ShoppingListSpecificItemViewHolder)?.specificItemFrontView
}
}
这是我的代码,它的工作正常,当我交换到左边和50%以上,那么我得到回调,但我想当我交换删除25%,那么我们应该删除文本,它应该留在交换模式,当我点击删除文本,那么它应该得到回调删除请帮助我,我们如何才能实现这一点。
1条答案
按热度按时间2wnc66cl1#
您可以尝试this方法,首先检查您正在滑动的组件/屏幕的宽度/高度。