Getting Android RecyclerView to update view inside React Native component

I am creating a mobile application using React Native and the list components included in it do not have high enough performance, so I started using Android RecyclerView as a list component. There is a problem though with this. RecyclerView does not update its content views until it scrolls or resizes the RecyclerView. What can cause this problem and how can I fix it? I tried notifyDatasetChanged, notifyItemChanged, forceLayout, invalidate, postInvalidate and a lot of different options with each.

+8
android react-native android-recyclerview react-native-android
source share
1 answer

enter image description here Try this this.setIsRecyclable(true);

He will refer to your submissions.

 public class MainActivity extends AppCompatActivity { private RecyclerView mRecyclerView; private ArrayList<String> mSingleItemLists = new ArrayList<>(); private SingleListItemAdapter mSingleListItemAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_single_item); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(linearLayoutManager); setDummyData(); } private void setDummyData() { for (int i = 0; i <= 30; i++) mSingleItemLists.add("item" + i); } @Override protected void onResume() { super.onResume(); mSingleListItemAdapter = new SingleListItemAdapter(mSingleItemLists); mRecyclerView.setAdapter(mSingleListItemAdapter); } class SingleListItemAdapter extends RecyclerView.Adapter<SingleListItemAdapter.SingleListItemHolder> { private ArrayList<String> mSingleItemLists; private SingleListItemAdapter(ArrayList<String> singleItemLists) { mSingleItemLists = singleItemLists; //You can do notifydatasetchange if ur having any saved value } @Override public SingleListItemAdapter.SingleListItemHolder onCreateViewHolder(ViewGroup parent, int viewType) { View inflatedView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.row_recyclerview, parent, false); return new SingleListItemHolder(inflatedView); } @Override public void onBindViewHolder(SingleListItemAdapter.SingleListItemHolder holder, int position) { holder.mItemDate.setText(mSingleItemLists.get(position)); } @Override public int getItemCount() { return mSingleItemLists.size(); } class SingleListItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener { private TextView mItemDate; SingleListItemHolder(View v) { super(v); mItemDate = (TextView) v.findViewById(R.id.textview_recycler_list_item); v.setOnClickListener(this); this.setIsRecyclable(true); // This will help u } @Override public void onClick(View v) { //do your stuff notifyDataSetChanged(); } } } } 
+1
source share

All Articles