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
6
votes
2 answers

viewHolder.getAdapterPosition() always returns -1

For some reason I'm not able to use holder.getAdapterPosition() because it always returns -1 but holder.getLayoutPosition() returns a position just fine. My onCreateViewHolder: @Override public ViewHolder onCreateViewHolder(ViewGroup parent, …
6
votes
1 answer

ViewHolder not as a inner class

Can the RecyclerView.ViewHolder be used not as a inner class? Are there any issues on doing so? I have searched around but havent found any documentation on it!
ivoencarnacao
  • 137
  • 1
  • 1
  • 7
6
votes
1 answer

how to use view holder if custom listview row content are dynamic?

i have create custom list view using base adapter to dynamic row content.row content are created programmatically (check box,text view) they are include in layout. problem to scrolling time they are very slow because not use view holder. …
5
votes
1 answer

Cannot find method getBindingAdapterPosition() in RecyclerView.ViewHolder

The RecyclerView docs mentions a public method - getBindingAdapterPosition. https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder#getBindingAdapterPosition() But i cannot seem to find it. What am i missing?
Amit Jayant
  • 2,501
  • 2
  • 29
  • 38
5
votes
1 answer

Performance of ConstraintLayout inside RecyclerView ViewHolder

I've spent the last 2 days attempting to triage why my RecyclerView is so is so unbearably slow while scrolling and I've narrowed it down to the ConstraintLayout I'm using for the rows. Using the GPU profiler on android shows green/blueish green…
5
votes
1 answer

how to scroll to next item by clicking on a checkbox in each item (recyclerview)

Forgive me for my English. My list contains 100 items. Each item consists of two checkboxes and I want to scroll to the next item each time a checkbox is clicked. please give me the best answer link If this question has already been answered this is…
5
votes
2 answers

Cannot call runOnUiThread()

I have a fragment called MyRequestFragment, that contains a RecyclerView and binding the data to the RecyclerView using onBindViewHolder() using my adapter class. Now every ViewHolder I have a button. and for every click on the button a POST…
nifCody
  • 2,394
  • 3
  • 34
  • 54
5
votes
2 answers

RecyclerView - get Position inside Activity rather than RecyclerViewAdapter

It is my third day now dealing with the handling of my view clicks. I originally was using ListView, then I switched to RecyclerView. I have added android:onclick elements to every control on my row_layout and I am handling them in my MainActivity…
John Anderson
  • 124
  • 1
  • 1
  • 9
5
votes
1 answer

Android - passing data to ViewHolder constructor in onCreateViewHolder(..)

I have a RecyclerView and I'd like to pass data to the RecyclerView.Adapter's ViewHolder's constructor in onCreateViewHolder(ViewGroup parent, int viewType). What I'd like to do is pass a parameter (the data item itself) to the ViewHolder's…
user1841702
  • 2,683
  • 6
  • 35
  • 53
5
votes
3 answers

Android DataBinding in RecyclerView.ViewHolders with different layouts

I'm trying to use androids databinding feature in new project and so far very happy with it. But now i came across a problem in my recyclerviews viewholder. My viewholder uses different layouts (based on the viewtype when it gets created) public…
hightower
  • 105
  • 1
  • 8
5
votes
6 answers

ListView setText on particular position

I defined the following code to be able to set text in a certain position. if(position == 0) { holder.text.setText("blah"); } What I would like is to check if the position is equals 0, and then if it is, set text on…
dynamitem
  • 1,647
  • 6
  • 25
  • 45
5
votes
1 answer

Butter Knife view holder pattern in custom adapter

I'm trying to use Butter Knife in a custom adapter like the documentation advertises: http://jakewharton.github.io/butterknife/ I pasted the example code and inserted the layout with my RelativeLayout file: @Override public View getView(int…
user3105453
  • 1,881
  • 5
  • 32
  • 55
5
votes
1 answer

Why to use static with RecyclerView.ViewHolder

Why is recommended to use static for a class extended from RecyclerView.ViewHolder if I create a new instance of this class on the onCreateViewHolder method and I guess that instance is used for each item: @Override public RecyclerViewHolder…
marco2704
  • 90
  • 2
  • 9
5
votes
2 answers

Displaying an AlertDialog in ViewHolder in a RecyclerView Adapter class

I've implemented a RecyclerView with some rows and I'm now trying to use AlertDialog to display a message when the user taps on a row. I've successfully implemented the setOnClickListener in the Adapter but I can't get the AlertDialog to work, the…
5
votes
1 answer

Changing the size of a view in OnLayoutChangeListener

I've implemented a gallery using the recyclerview and I've added an onLayoutChangeListener to the viewholder so that once the layout is calculated, the height of the imageview is changed to match the image's aspect ratio. It works fine when first…