0

I have:

public class RecyclerAdapter extends ListAdapter<Cars, RecyclerAdapter.RecHolder>{
        public TextView name_product1;
        public TextView category_product1;

  class RecyclerHolder extends RecyclerView.ViewHolder {
        public TextView name_product;
        public TextView category_product;

     public RecHolder(@NonNull final View itemView, final Recycler_Adapters_items listener) {
          name_Product = itemView.findViewById(R.id.field1);
          category_Product = itemView.findViewById(R.id.field2);
     }
   }
}

Then:

public void onBindViewHolder(@NonNull RecHolder holder, int position) {
     holder.name_product.setText(currentItem.getname_product());
     holder.category_product.setText(currentItem.getcategory_product());
}

Later in other method in adapter but apart from class RecyclerHolder I need to call:

name_product.setTextSize();
category_product.setTextSize();

The problem is that:
name_product and category_product are not visible in those methods.
If I initialize it only in adapter (without RecyclerHolder then I can't call:

public void onBindViewHolder(@NonNull RecHolder holder, int position) {
     holder.name_product.setText(currentItem.getname_product());
     holder.category_product.setText(currentItem.getcategory_product());
}

Beacuse variables are not visible.
The simple but "weak" solution is to do it like this:

 public RecHolder(@NonNull final View itemView, final Recycler_Adapters_items listener) {
          nameProduct = itemView.findViewById(R.id.field1);
          category_Product = itemView.findViewById(R.id.field2);
          name_product1 = name_product;
          category_product1 = category_product;
     }

But it doesn't satisfy me.
How can I see the same variables in both methods in Adapter and class RecyclerHolder?

Rivke
  • 25
  • 5

1 Answers1

0

from where are you calling that method which executes

name_product.setTextSize();
category_product.setTextSize();

one solution is while calling the method pass the view as parameter

RahulK
  • 79
  • 1
  • 5
  • Yes, I was thinking about this... I wanted to do it with "this" keyword, but compiler tells that: "Variable is already assigned to this value ". – Rivke Jun 24 '22 at 12:51