neustart47 neustart47 - 1 year ago 73
Android Question

Changing text in TextView inside CardView from itself

Imagine a CardView with a button and text field. When I press on a button, text should change in the textfield. Code for my recyclerView is given below, where I am setting the text and a listener for a button:

public void onBindViewHolder(CategoriesDetailedViewHolder holder, int position) {

final CategoryDetailedModel model = categoriesDetailedModels.get(position);

holder.btnPlus.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
holder.description.setText("some text");

The main problem is with the string:

holder.description.setText("some text");

It cannot be accessed from an inner class.
Is anyone have any idea how to change text in card view from itself.

Update 1

public class CategoriesDetailedViewHolder extends RecyclerView.ViewHolder{
CardView cv;
TextView description;
TextView positiveCounter;
TextView negativeCounter;
TextView btnPlus;
View negativeCounterWrapper;
View positiveCounterWrapper;
CategoriesDetailedViewHolder(View itemView) {
cv = (CardView)itemView.findViewById(;
description = (TextView)itemView.findViewById(;
positiveCounter = (TextView)itemView.findViewById(;
negativeCounter = (TextView)itemView.findViewById(;
btnPlus = (TextView)itemView.findViewById(;

positiveCounterWrapper = itemView.findViewById(;
negativeCounterWrapper = itemView.findViewById(;

public CategoriesDetailedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.categories_detailed_list_row_view, parent, false);
CategoriesDetailedViewHolder pvh = new CategoriesDetailedViewHolder(v);
context = parent.getContext();
return pvh;

Answer Source

Instead of,

TextView description;

Make it,

public TextView description;

EDIT: Change the following,

    public void onBindViewHolder(CategoriesDetailedViewHolder holder, int position) { ... }


    public void onBindViewHolder( final CategoriesDetailedViewHolder holder, int position) { .... }