vtking vtking - 1 year ago 83
Android Question

how to change background of a row (special) in listview with MainActivity extends ListActivity

I have a project, which have MainActivity extends ListActivity.
I want change background color of a row in listview.
I can change if MainActivity is extend Activity and I have a CustomAdapter. Then I override a method getView(), then i can do it.

But i haven't way to change it with my project now, i can't override method getView(). please show me a way.

I'm sory if the artice is ambigouos.

Answer Source

MyAdapter class:

    public View getView(int position, View convertView, ViewGroup parent) {
    // View view= super.getView(position, convertView, parent);
    // if (position == 0) {
    // view.setBackgroundColor(Color.GRAY);
    // }

    // TODO Auto-generated method stub
    int pos = position;
    View row = convertView;
    WeatherHolder holder = null;

    if (row == null) {

        LayoutInflater inflater = ((MainActivity) context)
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new WeatherHolder();
        holder.imgIcon = (ImageView) row.findViewById(R.id.imgIcon);
        holder.txtTitle = (TextView) row.findViewById(R.id.txtTitle);

    } else {
        holder = (WeatherHolder) row.getTag();
    Weather weather = data[position];
    if (position == 0) {

    return row;

static class WeatherHolder {
    ImageView imgIcon;
    TextView txtTitle;

and they show at positon:0, 8, 16,... I want it show only postion:0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download