以下の私のコードでは、アイテムに写真があればいいでしょう。ただし、空の場合、アイテムの画像はサイズ 70 dp の空のボックスに見えます。アイテムに画像が含まれていない場合は、空のボックスが自動的に TextView で満たされるので、空の場合は画像が ImageView ではなく、TextView のみのようになります。ImageView の幅サイズを設定しようとしました android:layout_width="wrap_content" 希望どおりに機能しましたが、画像のサイズが乱れました。ワイドとスモールがあります。そのため、フラットに見えるように 70 に設定しました。
これは私のコードです:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<ImageView
android:id="@+id/logo_article"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip" />
<TextView
android:id="@+id/title_article"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/logo_article"
android:gravity="center_vertical"
android:text="Title Article" />
</RelativeLayout>
データベースからアイテムを取得し、Java のコードである単純なアダプターに格納します。
String[] from = { "title", "logo" };
int[] to = { R.id.title_article, R.id.logo_article };
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(),listkatdb,R.layout.per_item_list, from, to);
kategoriListView.setAdapter(adapter);
adapter.notifyDataSetChanged();
ありがとう。