0

これまでに作成しました。アイテムが表示されています。行と同じ数の要素を持つ配列にキー値があると仮定しましょう。16行ある場合、配列には16個の要素があります。array [0]をチェックし、最初の行のsetColorの値に応じて、次にarray[1]と次の行のsetColorをチェックします。誰かが私を助けることができます:

public class SimpleAdapter extends ArrayAdapter<String>{

private final Context context;



private String data[] = null;

    public SimpleAdapter(Context context,  String[] data) {
        super(context, R.layout.row, data);
        this.context = context;
        this.data = data;
    }



  @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.row, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.text1);
        textView.setText(data[position]);
        return rowView;
    }
}
4

2 に答える 2

0

getView()では、次のようなものを使用できます。

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.row, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.text1);
textView.setText(data[position]);

switch(position) {
  case 0:
   rowView.setBackgroundColor(color0)
   break;
  case 1:
   rowView.setBackgroundColor(color1)
   break;
...
}

return rowView;
于 2012-01-13T15:56:27.337 に答える
0

color/(background drawable)配列で定義するのは簡単です。お気に入り

int[] color = {your colors };

次に、以下の行を使用します

int mycolor = position % color.length;
rowView.setBackground/color = color[mycolor];
TextView textView = (TextView) rowView.findViewById(R.id.text1);
textView.setText(data[position]);
return rowView;
于 2012-01-13T15:57:00.773 に答える