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
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…
20
votes
4 answers

Add fragment in RecyclerView.ViewHolder

I have a RecyclerView.ViewHolder which will add different fragment into its FrameLayout based on the instance of the object passed. The problem comes where it is almost impossible to add fragment into the ViewHolder. Take note that I already passed…
Ginsan
  • 291
  • 1
  • 5
  • 13
19
votes
3 answers

setAlpha() on onBindView in RecyclerView doesn't work on first display

Using the following code within a RecyclerView.Adapter: onBindViewHolder(VH holder, int position){ holder.itemView.setAlpha(0.5f); } Alpha will not be shown the first time the item is shown. However, if you leave the screen and come back, Alpha…
19
votes
8 answers

Dynamically adding Views in a RecyclerView only to current item

I'm dynamically adding Views to my items in a RecyclerView. These added Views should only be related to the item which they're added to, but I'm having a problem when I scroll. It seems the View is recycled and a new item is loaded, but those…
Orbit
  • 2,985
  • 9
  • 49
  • 106
17
votes
3 answers

Does RecyclerView.ViewHolder always have to be an inner class?

I have two RecyclerView.Adapters that are using exactly the same RecyclerView.ViewHolders as inner classes. I wanted to get rid of code duplication and made these ViewHolders free, separate class so the brand new class now can be used by any…
Egemen Hamutçu
  • 1,602
  • 3
  • 22
  • 34
16
votes
2 answers

RecyclerView itemView OnGlobalLayoutListener doesn't fire for all itemViews

I have a RecyclerView in whose view holder constructor I'm adding an onGlobalLayoutListener as follows public CustomViewHolder(final View itemView, Context context) { super(itemView, context); …
Aks
  • 5,188
  • 12
  • 60
  • 101
16
votes
3 answers

How to handle click-event in RecyclerView.ItemDecoration?

I have a RecyclerView (with LinearLayoutManager) and a custom RecyclerView.ItemDecoration for it. Let's say, I want to have buttons in the decoration view (for some reason..). I inflate the layout with button, it draws properly. But I can't make the…
Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95
16
votes
2 answers

Android: how can I insert a RecyclerView inside CardView?

The activity I am talking about must show a RecyclerView populated by CardViews as items. My goal is to show in every CardView a RecyclerView in its turn. Here my Activity's basic xml:
15
votes
3 answers

How to set two adapters to one RecyclerView?

I am developing an android app in which I'm storing two different types of information on 'FirebaseDatabase`. Then in the MainActivity, I'm retrieving them and showing to users in a RecyclerView. Both information are meant to be shown in different…
14
votes
2 answers

LiveData(MutableLiveData) and Databinding rise error (Failed to call observer method)

I have an app that uses ViewModel and MutableLiveData to bind live data to my UI. After hours westing my time! and review all sample on the internet I couldn't find the reason for the problem. My activity: public class DetailActivity extends…
14
votes
3 answers

RecyclerView.getChild(index) shows null when list is scrolled (index gets messed up)

I've been using SwipeableRecyclerView for my android application for enabling swipes for my recyclerView. RecyclerView contains a list of cardViews. I was trying to implement undo functionality for cards which will get deleted when swipe to left…
P-RAD
  • 1,293
  • 2
  • 15
  • 36
13
votes
1 answer

RecyclerView onBindViewHolder called multiple times for one item

I have used the RececlerView with the ViewHolder pattern for a while now. Im am implementing a custom Adapter. Im am not searching for a specific bug help in my code. I was just wondering, if it's normal, that the onBindViewHolder method is called…
Palm
  • 699
  • 1
  • 6
  • 17
13
votes
3 answers

What is the working of setTag and getTag in ViewHolder pattern?

I have a simple code snippet for implementing custom listview. My code is as follows: WeatherAdapter.java : public class WeatherAdapter extends ArrayAdapter{ Context mcontext; int mlayoutResourceId; weather mdata[] = null; …
xyz
  • 1,325
  • 5
  • 26
  • 50
12
votes
9 answers

Implement multiple ViewHolder types in RecycleView adapter

It's maybe a discussion not a question. Normal way to implement multiple types As you know, if we want to implement multiple types in RecyclerView, we should provide multiple CustomViewHolder extending RecyclerView.ViewHolder. For exmpale, class…
12
votes
3 answers

Binding in ViewHolder

This will be theoretical question. As everyone we use RecyclerView in many parts of the app. Sometimes RecyclerView contains different items, not only image for example, but ads, hints etc. And that's why we can use getViewType() method in Adapter.…
Nominalista
  • 4,632
  • 11
  • 43
  • 102
1
2
3
70 71