Jjreina
Jjreina

Reputation: 2703

Add image in listview

I´d like to add an image in a row of a ListView, this is my code:

ListView listViewProducts = (ListView) findViewById(R.id.listViewProducts);
ImageView iconMeat = (ImageView) findViewById(R.id.iconMeat);

String[] products = getResources().getStringArray(R.array.products);

for (int itemPos = 0; itemPos < listViewProducts.getCount(); itemPos++)
{
    if ( products[0].equals(listViewProducts.getItemAtPosition(itemPos)) )
    {
        //TODO
        // In this case to add the image 
    }
}

Thanks

Upvotes: 0

Views: 971

Answers (1)

Bette Devine
Bette Devine

Reputation: 1194

See these posts for using adapters in listview :- https://stackoverflow.com/a/8267165/2035885 http://www.ezzylearning.com/tutorial.aspx?tid=1763429&q=customizing-android-listview-items-with-custom-arrayadapter http://www.mkyong.com/android/android-listview-example/

Do following:-

  1. Create a custom adapter for listview.
  2. Create an array of drawables for populating the list.
  3. In your getView method of adapter populate the list according to index.

Upvotes: 1

Related Questions