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
12
votes
5 answers

How to call a MainActivity method from ViewHolder in RecyclerView.Adapter?

In a simple app project at GitHub I have only 2 custom Java-files: MainActivity.java contains Bluetooth- and UI-related source code DeviceListAdapter.java contains an Adapter and ViewHolder for displaying Bluetooth devices in a RecyclerView The…
11
votes
4 answers

How to detect each RecyclerView item after it is displayed

I want to detect each item in my RecylerView after it is displayed to the user. Basically, I am trying to play a sound on each item after it is loaded on the screen. But I am not able to detect whenever each item is loaded on the screen! Is there…
Dan
  • 2,086
  • 11
  • 71
  • 137
11
votes
1 answer

RecyclerView items disappear after switching between fragments

I have 4 fragments in my app, which managed in NavActivity: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nav); toolbar = (Toolbar) findViewById(R.id.toolbar); …
11
votes
5 answers

RecyclerView Recycled ViewHolder Image View wrong size

I have a recycler view with different View Holders. A couple of view holders have image views which I pass into Glide to display images. The problem is, when the recycler view starts recycling views, the imageview width/height are that of the…
DJ-DOO
  • 4,545
  • 15
  • 58
  • 98
11
votes
5 answers

Why does the input value in EditText swaps its position while scrolling in a RecyclerView?

After putting an input in the EditText, if a scroll up or down very fast the input values swaps its position in another EditText in a RecyclerView. Before scrolling the data was in the first EditText. After scrolling up and down the value of the…
11
votes
1 answer

RecyclerView Adapter and ViewHolder update dynamically

I am trying to make an app that will be loading news from the network and will be updating dynamically. I am using a RecyclerView and CardView to display the content. I use Jsoup to parse sites. I don't think that my code is needed because my…
10
votes
4 answers

Why is setAlpha() not working in RecyclerViews?

I am trying to change the transparency of item-views in a RecyclerView according to certain user inputs. if (quantity>0) { holder.itemView.setAlpha((float) 1); } else { holder.itemView.setAlpha((float) 0.65); } Changing alpha from 0.65 to 1…
10
votes
2 answers

DiffResult dispatching lead to 'Inconsistency detected. Invalid view holder adapter positionViewHolder' error sometimes

I have an RxJava2 Observable that takes two lists, calculate diff result for them and send this data to adapter. Adapter dispatch updates on Main Thread. Code of dispatching in adapter: public void dispatchStreams(List streams, @Nullable…
10
votes
2 answers

How can I use Android DataBinding in a listview and still use a ViewHolder pattern?

I have an Android activity that pulls its data from an observable list inside an adapter class. My getView() method in my adapter class is: @Override public View getView(int position, View convertView, ViewGroup parent) { if (inflater == null)…
Brett
  • 11,637
  • 34
  • 127
  • 213
10
votes
6 answers

Nested recylerview lag while first few scrolls and then scrolls smoothly?

I am using nested RecyclerView. Means inside a vertical RecyclerView I have multiple horizontal recycler view I am attaching adapter to horizontal recylerviews inside onBindViewHolder method of parent RecyclerView as follows. @Override public void…
10
votes
5 answers

Where should I place setOnClickListener in a RecyclerView Adapter

In tutorials on internet where they setOnClickListener in Adapter of RecyclerView they define it in two ways : either inside ViewHolder or inside BindViewHolder. My Question is which one is a better approach, Please recommend any another approach…
Anudeep Samaiya
  • 1,910
  • 2
  • 28
  • 33
10
votes
2 answers

ViewHolder - good practice

A little newbie question. Why should we initialize the ViewHolder in getView()? Why can't we initialize it in the constructor?
Gorets
  • 2,434
  • 5
  • 27
  • 45
9
votes
4 answers

How can I animate a child view in a recyclerView element after notifyItemChange() in onBindViewHolder()

I want to animate a textView inside a recyclerView to transition upwards when I call notifyItemChanged(position). This is my onBindViewholder() that is being called automatically when a change in the adapter occurs: @Override public void…
bcsta
  • 1,963
  • 3
  • 22
  • 61
9
votes
2 answers

How can I set OnClickListener to two buttons in RecyclerView?

In my android app I have one activity to show a RecyclerView in which each row is composed by a TextView and 2 buttons. Just like that: Well, following many explanations of internet I have made this Adapter: public class ListAdapter extends…
9
votes
1 answer

RecyclerView and java.lang.IndexOutOfBoundsException Invalid view holder adapter positionViewHolder

I have a RecyclerView that binds a grocery item. Adding the item works perfectly. However, when I try to delete the item the app crashes and I get the IndexOutOfBoundsException error. The problem I am facing is in my onBindViewHolder(). I tried to…
1 2
3
70 71