How to change background color of item in a list?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to change background color of item in a list?

Postby prajkti.khadse » Fri Mar 20, 2009 4:34 am

Hi all,
i've created a ListView using ArrayList and HashMap.
and now i want to apply different background color for every item int the list.
can anybody please help me out...???

Thanks in advance...

here's the code m working with.

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MyActivity extends Activity
{
static MyActivity myAct;
ListView myList;

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myAct = this;
myList = (ListView) findViewById(R.id.eab);

/*set click listener to handle
*click/touch/enter-key-pressed event*/
myList.setOnItemClickListener(new EabClickListener());

ArrayList<HashMap<String, String>> arrList = new ArrayList<HashMap<String,String>>();

HashMap<String, String> map = new HashMap<String, String>();
map.put(BUDDY_POTRAIT, R.drawable.annef+"");
map.put(BUDDY_NAME, "Anne Fisher");
map.put(BUDDY_STATUS,R.drawable.presence_busy+"");
arrList.add(map);

map = new HashMap<String, String>();
map.put(BUDDY_POTRAIT, R.drawable.superbob+"");
map.put(BUDDY_NAME, "Super Bob");
map.put(BUDDY_STATUS,R.drawable.presence_offline+"");
arrList.add(map);

map = new HashMap<String, String>();
map.put(BUDDY_POTRAIT, R.drawable.elizabeth+"");
map.put(BUDDY_NAME, "Elizabeth ");
map.put(BUDDY_STATUS,R.drawable.presence_online+"");
arrList.add(map);



String[] titles = new String[]{BUDDY_POTRAIT,BUDDY_NAME};
int[] ids = new int[]{R.id.POTRAIT,R.id.NAME};

SimpleAdapter myAdapter = new SimpleAdapter(this,arrList,R.layout.rel,titles,ids);
myList.setAdapter(myAdapter);


}

static final String POTRAIT = "pic";
static final String NAME = "name";

}

and the xml code is :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget33"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<ImageView
android:id="@+id/POTRAIT"
android:layout_width="130px"
android:layout_height="60px"
android:layout_alignParentTop="true"
android:layout_marginTop="10px"
android:layout_alignParentLeft="true"

/>

<TextView
android:id="@+id/NAME"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/POTRAIT"
android:textStyle="bold"
android:textColor="#000000"
/>


</RelativeLayout>
prajkti.khadse
Developer
Developer
 
Posts: 32
Joined: Thu Mar 19, 2009 1:01 pm
Location: Bangalore

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests