Reputation: 119
I have a piece of code that adds / update the content of the card view that resides in a recycler view.
However, it doesn't update the content even though I have called
viewAdapter.notifyItemChanged(position);
and
viewAdapter.notifyItemChanged(position);
I have tried calling it in runOnUiThread method but it still does not update. I tried stepping into onBindViewHolder() and the values are updated inside but the display on the screen just won't get updated.
Any idea why? Some of my code below:
rvTransactionItems = (RecyclerView) mView.findViewById(R.id.rvTransactionItems);
rvTransactionItems.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(getParentActivity());
rvTransactionItems.setLayoutManager(llm);
detailAdapter = new DetailAdapter();
rvTransactionItems.setAdapter(detailAdapter);
@Override
public void onBindViewHolder(DetailViewHolder viewHolder, int i) {
StockCount count = addedItemCount.get(i);
Integer expectedQty = count.getExpectedQuantity();
Integer quantity = count.getQuantity();
viewHolder.tvArticleNumber.setText(articleNumber);
viewHolder.tvStockCode.setText(stockCode);
String countStr = quantity + " / " + expectedQty;
viewHolder.tvCount.setText(countStr);
}
Upvotes: 3
Views: 1317
Reputation: 119
I figured out how to solve my issue. The problem root was that my function calling the handler(protected Handler updateUiHandler = new Handler(Looper.getMainLooper());) that had to notify the adapter was in another thread. So basically I'm trying to run something on the main thread in another thread. So I have to go up the call hierarchy to invoke the method to be runOnUiThread. That will solve the issue.
So in conclusion, the notifyChange method must run on the main thread for the change to be effect!
Upvotes: 1