2017-06-30 6 views
0

私はRecyclerViewにいくつかのアイテムがあります。
私は(スクロールなし)のアイテム上のすべてのImageViewのイメージを変えたい
onBindViewHolderで私の一部のコードは次のとおりです。
Android RecyclerViewすべてのアイテムを変更imageviews

int count = parent.getChildCount(); 
v = parent.getChildAt(position); 
while(i<count) 
    if (i != position) { 
     v = parent.getChildAt(i); 
     ImageView imageView1 = (ImageView) v.findViewById(R.id.imgPlaySound); 
     imageView1.setImageResource(R.mipmap.playsound); 
     LinearLayout linearSeek1 = (LinearLayout) v.findViewById(R.id.linearSeek); 
     linearSeek1.setVisibility(View.GONE); 
    } 
    i++; 
} 

この部分のコードは正常に動作しますが、私は私のRecyclerViewにいくつかの項目を追加した場合されそして私のコードは私のすべての項目
マイカスタムRecyclerViewクラスにアクセスすることはできません私の項目をスクロールすると、アクティビティコードの別のファイル

+0

RecyclerViewは、ユーザーがスクロールやリサイクルなど、すべてのビューを作成し、自分の意見をArrayListのをループしを設定することができ、今この

@Override public void onBindViewHolder(final ViewHolder holder, final int position) { views.add(holder) } 

を行いますユーザーがスクロールしたビュー(したがって、recyclerviewという名前)。ユーザーに現在表示されているビューのみを更新できます。また、ViewHolderを使用してすべてのビューを保持し、 'holder'インスタンス(holder.imageview.setImageResource(...))を介してアクセスする必要があります。 朗読: - http://www.androidhive.info/2016/01/android-working-with-recycler-view/ - https://developer.android.com/guide/topics/ui/layout/ recyclerview.html – GurpreetSK95

+0

ありがとう、私は完全なRecyclerViewを持って、それは動作しますが、私はその問題があります –

答えて

0

がonBindViewHolderからの編曲に各ビューを追加していますayListこのArrayListをループし、アクションを実行します。上のその後

ArrayList<ViewHolder> views = new ArrayList<>();//call in the constructor make it a class variable so it can accessed globally; 

あなたの「onBindViewHolder」あなたは

int count = views.size(); 
for(int i=0; i<count; i++) 
{ 
    YourViewHolder v = views.get(i); 
    //call imageview from the viewholder object by the variable name used to instatiate it 
    ImageView imageView1 = v.imageViewFromHolder; 
    imageView1.setImageResource(R.mipmap.playsound); 
    LinearLayout linearSeek1 = v.linearLayoutFromHolder 
    linearSeek1.setVisibility(View.GONE); 
} 
関連する問題