views:

39

answers:

1

Hi, I want to create a ListView which contains a RelativeLayout which contains an ImageView and another Layout (Linear). Linear Layout Contains some TextView.

How can I create this ListView??

Thanks Deepak

A: 

You can make a layout for the rows. Let's say the ImageView is R.id.image an the TextView R.id.text. The row layout is R.id.row_layout For the list you need a list adapter. If you use a ListActivity it might look like this:

@Override
protected void onCreate(Bundle savedInstanceState){
    ...
    ArrayList<HashMap<String, Object>> listData = new ArrayList<HashMap<String, Object>>();
    HashMap<String, Object> m = new HashMap<String, Object>();
    m.put("image", R.drawable.some_image);
    m.put("text", "Test");
listData.add(m);
    adapter = new SimpleAdapter(this, 
            listData, R.layout.row_layout,
        new String[] {"image", "text"},
        new int[] {R.id.image, R.id.text});
    setListAdapter(adapter);
}

The ArrayList contains all data for the list. Every row is represented by a HashMap and the keys of the data have to be equal to the ids where you want to display them. In the adapter you say that the key image is mapped to your ImageView and so on.

yaourt