I've got My RecycletView.Adapter which has a field of Type ArrayList to set my Holder (inner class). If I try to update my Adapter from the Adapter class itself (OtherAdapter in my example) by setting the ArrayList and notifyDataSetChanged() it works perfect. The problem occurs when i try to update it (the exact same way) from my adapter from another class (in my case another Adapter but it shouldn't matter), it won't work.
I tried to not call the setter directly from the other class, passing through another method, but altough the function calls work fine, it won't work anyway.
The class which is not working is:
public class TavoliAdapter extends RecyclerView.Adapter<TavoliAdapter.TavoliHolder>{
private OtherAdapter theOtherAdapter;
@NonNull
@Override
public TavoliAdapter.TavoliHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.fragment_tavolo, parent, false);
return new TavoliAdapter.TavoliHolder(v);
}
@Override
public void onBindViewHolder(@NonNull TavoliAdapter.TavoliHolder holder, int position) {
holder.txtIdTavolo.setText(Integer.toString(tavoli.get(position).getIdTavolo()));
holder.txtPosti.setText(Integer.toString(tavoli.get(position).getPosti()));
holder.txtIdTavolo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
theOtherAdapter.setArrayList(new ArrayList<Stuff>());
}
});
//TavoliHolder is defined down here, skipping this part
}
The class to be changed is:
public class TavoliAdapter extends RecyclerView.Adapter<TavoliAdapter.TavoliHolder>{
private ArrayList<Stuff> list;
//Other stuff and HoldeClass of course
public void setArrayList(ArrayList<Stuff> list){
this.list = list;
notifyDataSetChanged();
}
}
I tried every type of change in the code it just doesn't work when i try to update from outside the class.