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.

1064 questions
457
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
  • 59,186
  • 91
  • 226
  • 333
83
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,544
  • 4
  • 27
  • 38
63
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
  • 993
  • 2
  • 10
  • 23
57
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…
53
votes
3 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,768
  • 25
  • 76
  • 131
35
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,879
  • 2
  • 16
  • 18
33
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…
33
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
  • 397
  • 1
  • 6
  • 11
32
votes
6 answers

How open fragment from RecyclerView.Adapter

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 getFragmentManager(): FragmentTransaction…
30
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…
30
votes
4 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
  • 11,633
  • 6
  • 46
  • 69
27
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,886
  • 4
  • 24
  • 28
24
votes
3 answers

Getting position of View in onCreateViewHolder

I am using a RecyclerView with a single row layout with an ImageView and a TextView. I want to implement a OnClickListener for the View and not for seperate ViewHolder objects. How can i get the position of the view in the Adapter? Right now i'm…
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
  • 13,144
  • 17
  • 71
  • 106
22
votes
6 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
  • 371
  • 1
  • 3
  • 13
1
2 3
70 71