I've a problem with a proyect I'm creating with Android Studio.
I have a tab layout with two fragments inside and an adapter that show products in a recycler view. The adapter is inside the fragment and is also the one that's responsible for showing the products, but I have the options to sort the list in the activity, and I can't access the adapter from the activity to reorder the list.
This is my code to sort the list,I have this on the model of the product. (I think this is not the problem)
public static Comparator<ProductoModelo> ProductoAZ = new Comparator<ProductoModelo>() {
@Override
public int compare(ProductoModelo p1, ProductoModelo p2) {
return p1.getNombre().compareToIgnoreCase(p2.getNombre());
}
};
And in my Tab activity I have the options in a menu, locate in the toolbar. (This is the problem)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.opciones_ordenar:
Collections.sort(adapterLista.getList(), ProductoModelo.ProductoAZ);
adapterLista.notifyDataSetChanged();
return true;
I know I'm doing something terrible wrong, but I can't see it. How can I access from tab activity to the list on my fragment?
I've tried setting the methods and variables in public and creating the variables in the activity, but it's still not working.