Questions tagged [android-viewholder]

A ViewHolder object stores each of the component views inside the tag field of the Layout, so you can immediately access them without the need to look them up repeatedly. The ViewHolder pattern is often used in Android applications to improve performances of view access.

A ViewHolder object stores each of the component views inside the tag field of the Layout, so you can immediately access them without the need to look them up repeatedly. The ViewHolder pattern is often used in Android applications to improve performances of view access.

For an example, check the official Android documentation on the ViewHolder pattern.

993 questions
438
votes
7 answers

What is the main purpose of setTag() getTag() methods of View?

What is the main purpose of such methods as setTag() and getTag() of View type objects? Am I right in thinking that I can associate any number of objects with a single View?
Eugene
  • 55,777
  • 85
  • 212
  • 324
73
votes
3 answers

What difference between static and non static viewholder in RecyclerView Adapter?

What are the advantages of this approach (using static nested class in my class MyAdapter extends RecyclerView.Adapter): static class MyVH extends RecyclerView.ViewHolder {...} And this approach (using member inner class): class MyVH extends…
Lester
  • 2,284
  • 4
  • 25
  • 36
55
votes
3 answers

What's better? notifyDataSetChanged or notifyItemChanged in loop?

So I have an activity with RecyclerView and I want to change TextView of every item in the RecyclerView by pressing button that has onClickListener() in the activity. I'm wondering what is better in terms of performance: Use notifyDataSetChanged…
Daniel
  • 873
  • 2
  • 9
  • 20
48
votes
4 answers

What is the benefit of ViewHolder pattern in android?

When you are developing an Android program; and you want to have a ArrayAdapter you can Simply have a Class (most of times with ViewHolder suffix) or directly inflate your convertView and find your view by id. So What is the benefit of using…
32
votes
6 answers

Where should I unbind ButterKnife 8.x.x in a ViewHolder?

I have a RecycleView.ViewHolder class which use ButterKnife annotations. Should my code unbind() in this ViewHolder class too? public class AView extends RecyclerView.ViewHolder { @BindView(R.id.a_text_view) TextView aText; public…
32
votes
3 answers

RecyclerView - callback when view is no longer visible

I have a RecyclerView with its Adapter and LayoutManager. Adapter has approximate 15 different ViewHolders. One of them contain WebView which loads external contents (99% of them are videos outside of YouTube). The problem comes when any View of…
mroczis
  • 1,699
  • 2
  • 14
  • 16
30
votes
5 answers

Android: RecyclerView content messed up after scrolling

I'm using RecyclerView to display a list of marks, and each mark of the value is shown as a CardView. But some contents of the cards are lost after the scrolling the RecyclerView down and scrolling back, as shown in the two screenshots below. The…
Swisyn
  • 367
  • 1
  • 6
  • 11
29
votes
6 answers

How open fragment from RecyclerView.Adapter

1.TabLayout - tab1 (Fragment1) - tab2 (Fragment2) - tab3 (Fragment3) * RecyclerView + CardView (OnClick) On CardView ClickListner open another fragment in tab3. So how to open fragment in tab3. Error is in…
27
votes
2 answers

Showing status for the last list item in a ListView using ViewHolder

int globalPosition ; .............. buttonAllData.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub new…
Sun
  • 6,258
  • 22
  • 69
  • 124
26
votes
7 answers

How to make RecyclerView stops recycling defined positions?

My problem is: I have a video streaming happening on one of the views inside the RecyclerView. When the user scrolls, the view gets recycled and other cameras starts their own streaming on that recycled viewholder. This is bad for user interface…
26
votes
6 answers

onBindViewHolder() is never called on view at position even though RecyclerView.findViewHolderForAdapterPosition() returns null at that position

I have a list with 13 items (although items may be added or removed), positions 0-12. When the fragment containing the RecyclerView is first shown, only positions 0 through 7 are visible to the user (position 7 being only half visible). In my…
young_souvlaki
  • 1,382
  • 3
  • 18
  • 25
23
votes
2 answers

Why in ViewHolder pattern should the ViewHolder class be static?

I am just trying to have a better understanding of the following pattern I regularly use to optimize ListView My readings only pointed me to the fact that a static inner class is treated as top level class. What is the benefit of such a thing…
znat
  • 12,164
  • 14
  • 60
  • 93
22
votes
3 answers

onCreateViewHolder of RecyclerView.Adapter is called twice or more, multiple times

I'm currently developing an application which uses RecyclerView. On reviewing LogCat I noticed that onCreateViewHolder was called twice after it was instantiated. 09-22 05:22:55.209 V/Adapter﹕ Construct 09-22 05:22:55.213 V/Adapter﹕…
hata
  • 8,429
  • 5
  • 32
  • 57
21
votes
2 answers

RecyclerView onCreateViewHolder Return Type Incompatibility With Multiple Custom ViewHolders

I'm trying to use multiple ViewHolders in a RecyclerView in order to swap these views out at run time. I have created two classes which extend RecyclerView.ViewHolder: MenuItemViewHolder public class MenuItemViewHolder extends…
19
votes
5 answers

ViewHolder views must not be attached when created

I'm trying to create a simple RV that will show a TextView. This is my adapter: public class MyRvAdapter extends RecyclerView.Adapter { private String[] mDataset; public static class ViewHolder extends…
Nakash.i
  • 317
  • 1
  • 3
  • 12
1
2 3
66 67