On my code below would've been nice if the item has a picture. but if it is empty then the item picture looks empty box the size 70dp. I would like if the item does not contain an picture, then automatically the empty box filled with TextView, so if it is empty then the picture like no ImageView, only TextView. I tried to set the ImageView width size andoid:layout_width="wrap_content" it worked with what I want, but the size of the picture was disheveled. There are wide and small. therefore I set it so the 70 to make it look flat.
This is my code:
<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>
I get items from database and I store to simple adapter, code in 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();
Thanks.