アダプタを使用して子ビューを再利用しているGridViewがあります。それぞれの子ビューは、上に重ねてTextViewを持つImageViewで構成されています。私が見ている問題は、スクロールして新しい画像を表示すると、グリッド内の他のセルの画像も表示される画像に変わることがあります。GridViewはまだ表示されている子ビューをリサイクルします
私は新しい行が見えてくるとき、getViewメソッドは、()新しい行のビューを取得するためのアダプタで呼び出されるためであると見ることができ、デバッグした後。しかし、ビューはメソッドに渡され、アンドロイドは私がリサイクルしたい、実際にはまだ見ている。だから、私が与えるビューのイメージを更新すると、グリッド内の別のアイテムのイメージも変わってしまいます。
これを引き起こす可能性があることは誰にも分かりますか?
活動
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/snapshot_list_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_snapshot_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.vellocet.snapshotviewer.SnapshotListActivity">
<GridView
android:id="@+id/snapshot_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:drawSelectorOnTop="true"
android:gravity="center"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:focusable="true"
android:clickable="true"/>
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
アダプタ:任意の助け
アダプターコード全体ですか?また、リサイクルされたビューがまだ画面上に表示されているとはどのように判断しましたか? – Karakuri
これは、GetSnapshotCallback実装と、子ビューでクリックリスナーを設定するコードを除いたものです。 getViewに渡されたビューのタグには、一番上の行の項目の1つのタグが含まれているため(スクロールしている場合)、まだ表示されています。 – dco123
また、デバッガで渡されたビューのオブジェクトIDは、以前に作成されたものと一致します。 – dco123