【发布时间】:2022-01-02 06:22:28
【问题描述】:
我正在尝试扩展 RecyclerView 以进行我自己的某些修改。这是我目前拥有的:
public class FeedRecyclerView extends RecyclerView {
private int currentClickedItem = -1;
public FeedRecyclerView(@NonNull Context context) {
super(context);
init();
}
public FeedRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
public FeedRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
// Check if item in RecyclerView is clicked
// If so, update "currentClickedItem" to the correct position
}
当用户点击 RecyclerView 中的某个项目时,我想更新上面代码中currentClickedItem 的值。我会用什么方法来做到这一点?
谢谢!
【问题讨论】:
-
这可以通过使用适配器和一个接口来完成,为什么你需要一个自定义的 Recyclerview。好像走错了方向。
-
@RajenRaiyarela 我稍后将在 RecyclerView 中使用此值来跟踪 RecyclerView 中的哪些项目在滚动时在屏幕上可见,并将其与
currentClickedItem的值进行比较。 -
抱歉,我无法理解您究竟想要达到什么目的。也许其他人会指导/帮助你。
-
我很感激。
标签: android android-recyclerview