【发布时间】:2016-11-15 04:33:56
【问题描述】:
有没有办法仅根据给定位置获取特定项目的 recyclerview 的ViewHolder?
类似getViewHolder(position);。
public MyViewHolder getViewHolder(int position){
MyViewHolder holder = null;
/**
Find ViewHolder here...
If Found initialize the holder..
holder = ?
**/
return holder;
}
这个函数在我的适配器类中,我正在寻找一种方法来获取一个项目的ViewHolder,这样我就可以更改我的自定义项目eg. holder.setText("Hello World"); 的一个视图的值,我有货,我找不到这样做的方法,我试图搜索,但没有一个能帮助我。
有人吗?
【问题讨论】:
-
请评论投反对票的原因。
-
这可能会帮助您针对特定位置的查看器:stackoverflow.com/a/40240599/1263362
-
@Sayem - 谢谢你的链接,但你能解释一下它对我的问题有什么帮助吗?谢谢。
-
拿到view holder后你想达到什么目的?
-
@HendraWD - 嗨!这是我想要实现的目标:我有一个在后台运行的倒数计时器,每个项目都有不同的倒数计时器和持续时间,
When I close and reopen the application, the Texview that I want to show the duration is no longer updating,所以我猜我可以用Every seconds that count by the timer, Call the function in my adapter class that find the ViewHolder base on the given position, if it is found then set the textview with that holder of the current duration.解决它,例如。theFoundHolder.textviewDuration.setText("00:00:00").
标签: java android android-recyclerview