Reputation: 645
I want to create a listviewitem in a listactivity. The listviewitem will be a textview and an image.
But I have a case that there is no image to put in the imageview I will want the textview to take the whole listviewitem.
I do not want to use different XML layouts for these cases because I have same issue but with 3 images (n of the 3 can be shown).
I need some sample code for dynamic adding image views....
Also - I am using an adapter for this list...
Upvotes: 0
Views: 77
Reputation: 9
if(v==null)
{
v= generateView(Activity.this);
}
LinearLayout generateView(Context context){
LinearLayout lay = new LinearLayout(context);
TextView tv = new TextView(context);
lay.AddView(tv);
}
Upvotes: 0
Reputation: 1887
I have no time to post code, but you could do something like this:
EDITED:
Here is one layout to use as your itemLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView android:id="@+id/img_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Upvotes: 1