具有动态资源的自定义适配器,我想将它们添加到 arrayadapter<string> 中,以便我可以将 m 添加到适配器中

customadapter with dynamic resource and i want to add them in arrayadapter<string> so that i can add the,m into adapter

我想创建一个具有不同颜色 bg 的适配器,具有以下 src

主要来源:用于一种布局

adapter = (new colormyadapter(this, R.layout.list_item, R.id.product_name, values)));
               listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener()
                {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position,long id) 
                    {

子来源:

    package org.gritsys.health_client.client;

import java.util.ArrayList;

import com.example.health_client.R.color;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class colormyadapter extends ArrayAdapter<String>{
    private String[] list;

    public colormyadapter(Context context,int resource, int textViewResourceId,
             ArrayList<String> values) {
        super(context,resource, textViewResourceId);
        list = new String[values.size()];
        for (int i = 0; i < list.length; i++)
            list[i] = (String) values.get(i);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = (TextView)super.getView(position, convertView, parent);
        View view2;
        if(position%2==0)
        {

              view.setBackgroundColor(Color.parseColor("#FFD700"));
        }
        return view;
    }

}

resource:

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <!-- Single ListItem -->

        <!-- Product Name -->
        <TextView android:id="@+id/product_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="10dip"
            android:textSize="16dip"
            android:textStyle="bold"/>    

    </LinearLayout>

我想将数据列表添加到列表中并用不同的颜色标记它们 在其中使用不同的布局

 adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, values){
               @Override
               public View getView (int position, View convertView, ViewGroup parent){
                   View v = super.getView(position, convertView, parent);
                 if(position%2==0){
                   ((TextView)v.findViewById(R.id.product_name)).setTextColor(color.BlueViolet);
                 }
                   return v;
               }
           };
           listView.setAdapter(adapter);