You could do something like
public View getView(int position, View convertView, ViewGroup parent)
{
// Create a linear layout to hold other views
LinearLayout oItemViewLayout = new LinearLayout(mContext);
// ImageView
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setScaleType(ImageView.ScaleType.FIT_END);
i.setLayoutParams(new ListView.LayoutParams(60,60));
// Add ImageView to item view layout
oItemViewLayout.addView(i);
// TextView
TextView lblTextView = new TextView(mContext);
lblTextView.setText(mImageNames[position]);
// Add ImageView to item view layout
oItemViewLayout.addView(lblTextView);
return oItemViewLayout;
}
Where you have also defined an array of Strings to hold the names of the images, perhaps like
private String[] mImageNames = {"title of video3", "video5", "music2",};
It would be even easier if you create a layout for the ListItem and load that to create the view instead
Create a layout called say "mylistview.xml"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/ITEMVIEW_imgImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/ITEMVIEW_lblText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
You could then make the getView() method like this
public View getView(int position, View convertView, ViewGroup parent)
{
// Create a new view or recycle one if available
View oItemViewLayout;
if (convertView == null)
{
// New view needs to be created
oItemViewLayout = (View)LayoutInflater.from(mContext).inflate(R.layout.mylistview, parent, false);
}
else
{
// Recycle an existing view
oItemViewLayout = (View)convertView;
}
// ImageView
ImageView i = (ImageView)oItemViewLayout.findViewById(R.id.ITEMVIEW_imgImage);
i.setImageResource(mImageIds[position]);
// TextView
TextView lblTextView = (TextView)oItemViewLayout.findViewById(R.id.IITEMVIEW_lblText);
lblTextView.setText(mImageNames[position]);
return oItemViewLayout;
}
That will not only make life easier by allowing you design the view in XML but it will also be more efficient because you will re recycling views that have gone off screen but are still in memory because you are grabbing the convertView instance when there is one.