This might help as well,
write like this -> textView.setText(""+cartModels.size());
instead of -> textView.setText(cartModels.size());
TextView cartText = view.findViewById(R.id.cartTextDemo);
CartViewModel cartViewModel = ViewModelProviders.of(this).get(CartViewModel.class);
cartViewModel.getmAllCartsVM().observe(this, new Observer<List<CartModel>>() {
@Override
public void onChanged(@Nullable List<CartModel> cartModels) {
if (cartModels != null) {
//cartText.setText(cartModels.size()); // This will not work beacuse it is getting resource instead of string
cartText.setText(""+cartModels.size()); // this will give string
Log.d(TAG, "onChanged: onChanged Called: CartModels Count: "+cartModels.size());
}
}
});