Как изменить текстовое представление при просмотре карты - PullRequest
0 голосов
/ 13 мая 2019

в просмотре карты у меня есть просмотр изображений и два просмотра текста.У меня возникают проблемы при попытке выяснить, как изменить текст одного из текстовых представлений, когда кто-то нажимает на просмотр карт ... это вообще возможно?

Просмотр карт контролируется утилитой просмотра ....в общем, мне нужно около 20 просмотров карт.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    app:cardCornerRadius="5dp"
    android:foreground="?android:attr/selectableItemBackground">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp">

    <ImageView
        android:id="@+id/image1"
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:background="@color/transparent"
        android:padding="0dp"
        android:scaleType="fitCenter"
        android:src="@drawable/card1" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="20dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_marginTop="5dp"
        android:text="Text Here"
        android:textColor="@color/red" />

    <TextView
        android:id="@+id/product"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="SUV"
        android:textColor="@color/grey_font"
        android:textSize="11dp" />

Вот щелчок просмотра карты, я получаю позицию просмотра карты, но не знаю, как получить текстовое представление внутри просмотра карты..

public void onItemClick(int position) {
   Log.e(TAG, "Bien: " + position);
}

public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
    Items  currentItem = vReyclerViewList.get(position);

    String heading      = currentItem.getHeading();
    String title        = currentItem.getTitlee(); 

    holder.vHeading.setText(heading);
    holder.vTitle.setText(title);
}



public class RecyclerViewHolder extends RecyclerView.ViewHolder {

        public TextView title;
        public TextView product; 

        public RecyclerViewHolder(View itemView) {
            super (itemView);
            title       = itemView.findViewById(R.id.title);
            product         = itemView.findViewById(R.id.product); 

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(vListener != null) {
                        int position = getAdapterPosition();
                        if (position != RecyclerView.NO_POSITION) {
                            vListener.onItemClick(position);
                        }
                    }
                }
            });
        }
    }

1 Ответ

3 голосов
/ 14 мая 2019

Вы должны переопределить метод onBindViewHolder (), а затем реализовать, как показано ниже.

Override 
public void  onBindViewHolder(RecyclerViewHolder holder, int position) {
   Model model = getItem(position);
   holder.bind(model);
}

public class RecyclerViewHolder extends RecyclerView.ViewHolder {

  public final TextView title;
  public final TextView product;

  public RecyclerViewHolder(View itemView) {
    super (itemView);
    title    = itemView.findViewById(R.id.title);
    product  = itemView.findViewById(R.id.product);
  }

  public void bind(final Model model){
    itemView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
       title.setText(model.getText());
      }
    });
  }
}
...