Answer the question
In order to leave comments, you need to log in
How to notify RecyclerView that data has changed?
Good afternoon! When the focus is lost, the value is taken from the TextEdit and written to the database. How to notify RecyclerView that the data has changed and the view needs to be updated from the ViewHolder?
public class OrderViewHolder extends RecyclerView.ViewHolder {
public OrderCardBinding orderCardBinding;
DbHelper dbHelper;
public OrderViewHolder(View itemView) {
super(itemView);
dbHelper = new DbHelper(itemView.getContext());
orderCardBinding = DataBindingUtil.bind(itemView);
orderCardBinding.orderTitleEt.setOnFocusChangeListener((view, hasFocus) -> {
if (!hasFocus) {
dbHelper.renameTitleOrder(dbHelper.getAllOrders()
.get(getAdapterPosition()).id, orderCardBinding.orderTitleEt.getText().toString());
//вот здесь нужно уведомить RecyclerView что данные изменились и нужно обновить адаптер
}
});
}
}
Answer the question
In order to leave comments, you need to log in
I didn’t quite understand what you want
, if you want to take data from the database, then you can use ContentProvider (yes cursorprovider does not work with RecyclerView but there is https://gist.github.com/skyfishjy/443b7448f59be978bc59 )
you can use rxjava
you can EventBus
you can just forward the interface
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question