アイテムの動的リストを表示する必要があるレイアウトに取り組んでいます。各アイテムには、定義されたUUID、名前(バナーテキスト)、画像URL、および選択されているかどうかを示すブール値があります。これらを保持するPOJOも作成しました。アイテムをグリッドビューに配置するカスタムレイアウトを作成しました。2つのアイコンにバナーテキストが表示されています。次のようになります。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/ItemLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/ItemImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:background="@android:color/transparent" />
<ImageView
android:id="@+id/ItemOverlayImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:background="@android:color/transparent" />
<TextView
android:id="@+id/ItemTextBanner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#BF000000"
android:gravity="center"
android:textStyle="bold" />
</RelativeLayout>
</FrameLayout>
カスタムアダプタとアクティビティも作成しましたが、すべてのアイテムを読み込んで、画像をダウンロードしてビットマップにエンコードし、テキストバナーを設定しても問題ありません。問題は、アイテムがクリックされた場合に「選択された」状態と画像を変更したいということです。
を追加できることはGridView.setOnItemOnClickListener
わかっていますが、選択されたアイテムとその親ビューはわかっていますが、「選択された」状態を取得する方法がわかりません。 このリンクは、アダプターの静的リストからの状態を使用し、私がモデル化したものです。次のメソッドを追加して、から呼び出しましたGridView.setOnItemOnClickListener
。
public void itemSelected(View parent, int position)
{
if(items.get(position).isSelected())
{
ImageView interestSelected = (ImageView)parent.findViewById(R.id.ItemOverlayImage);
interestSelected.setImageResource(0);
}
else
{
ImageView interestSelected = (ImageView)parent.findViewById(R.id.ItemOverlayImage);
interestSelected.setImageResource(R.drawable.overlay);
}
}
最初の問題は明らかです。状態をitems配列に保存していませんが、これは簡単な修正です。本当の問題は、最初のアイテムだけがオーバーレイを取得することです。R.id.ItemOverlayImage
では、最初のアイテムだけでなく、選択したGridViewのアイテムのを変更するにはどうすればよいですか?それとも私はこれについて完全に間違っていますか?