Reputation: 169
I have recyclerview
in that i need to color 1st item's button
.
so that I use following way,after notifyDataSetChanged()
View viewItem = rvProductList.getLayoutManager().findViewByPosition(0);
but viewItem
is getting null
.
Is there any way of getting first items position?
Upvotes: 0
Views: 1156
Reputation: 500
Maybe the view at position 0 is recycled at certain position. If you want to test it clearly. Check null viewItem in two case:
Scroll your recycle view up to top, when you can see the 1st item. Then call this and check null
View viewItem = rvProductList.getLayoutManager().findViewByPosition(0);
UPDATE SOLUTION:
Solution is set the flag to know when you want to color 1st item. And in onBindViewHolder()
method do this
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
// I suppose that flag is true then we color 1st item
if(position == 0 && flag) {
// color your button here
} else {
// ...
}
}
Hope it help!
Upvotes: 1