私のプロジェクトにrecyclerView
を実装しました。Android:recyclerViewのビューの可視性を変更する
recyclerView
row
にはButton
があります。 recyclerView
の私の各行のコードは次のようである:
savedmessage_custom_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:background="#ffffff"
android:orientation="vertical">
<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Dummy text" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:visibility="gone"/>
</LinearLayout>
ボタンの視認性がgone
あります。私は誰かがそれの上にmessage
textView
をクリックすると、このボタンの可視性を「可視」に変更したいと思います。 message (textView)
に簡単なonClickLiestener()
を実装し、message
のクリックで表示の可否をbutton
に変更しました。それがうまくいかないことは分かっていましたが、結果を見たいと思っていました。結果は奇妙です。行1のtextViewをクリックすると、行7,17,19などのボタンものボタンが表示されます。私はこれがviewHolderのキャッシュのcozかもしれないと思います。
MyViewHolderはこのようなものである:誰かが私は私のrecyclerViewの、perticular行のだけ、ボタンの表示を変更することができますどのように私を導くことができる
class MyViewHolder extends RecyclerView.ViewHolder {
TextView message;
public MyViewHolder(final View itemView) {
super(itemView);
message = (TextView) itemView.findViewById(R.id.message);
message.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemView.findViewById(R.id.button).setVisibility(View.VISIBLE);
}
});
}
}
?
アダプタコードを記載してください。ボタンの可視状態をモデル化するためのプロパティを追加する必要があります。 –