0

I want to update the recyclerview adapter item's textview value dynamically with some data.

For that i'm doing this way:

View mRecyclerView = linearLayoutManager.getChildAt(viewPosition);

                TextView textView=(TextView) mRecyclerView.findViewById(R.id.text_number);
                Integer chatCount = Integer.parseInt(textView.getText().toString());
                chatCount++;
                textView.setText(chatCount + "");
                jobsFragmentRecyclerViewAdapter.notifyItemChanged(viewPosition);

But the above coding is working only for visible views on the screen, For the views that are not visible i'm getting a null pointer exception for mRecyclerView can anyone help me on how to get the recyclerview item that is not in focus

Thanks in advance

Manikanta
  • 3,421
  • 4
  • 30
  • 51

1 Answers1

0

Somewhere in your code you should have an adapter that populates the data of the RecyclerView. That adapter has a method called onBindViewHolder() that populates each ViewHolder. That's where you should code how each viewholder should look.

For example: you could have a list of Strings (one for each viewholder). onBindViewHolder would take one String and set the TextView text as that String. So changing one String of that list (and calling notifyItemChanged()) would be enough

Alberto S.
  • 7,409
  • 6
  • 27
  • 46
  • Thanks pelocho for responding, The solution you have provided is for initial setting up of data in adapter.but i what i want is to dynamically update the adapter item(exclusively) by giving its position to linearlayoutmanager(that is managing it) or recyclerview(that is holding) it .But all the methods getChildView(position) etc.. that are returning visible child. I want the the view that is not in focus by providing the index. I hope you have understood my question clearly – Manikanta Oct 30 '15 at 09:19
  • Yes, I did. The solution I gave works also for initial setting and updating items. Update the source of your data and call `notifyItemChanged()` (or `notifyDataSetChanged()` if you want to update everything) – Alberto S. Oct 30 '15 at 13:14