0

ListViewサーバーからのデータをjsonで表示するダイナミックを作成します。setBakgroundColorデータ内のオブジェクトに依存したい。例: json は

{"Order":[{"id":1,
"situation":"notchecked",
"status":"Processing"},
{"id":2,
"situation":"checked",
"status":"Processing"}]}

状況 == チェックされていない場合

convertView.setBackgroundColor(Color.GREEN);

これは BaseAdapter の私のビューです

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.complete_order_row, parent,
                    false);
                if ()......{

                convertView.setBackgroundColor(Color.GREEN);
                 }
        }


        TextView situation = (TextView) convertView
                .findViewById(R.id.situation);
        situation.setText(catList.get(position).getSituation());
         TextView status= (TextView) convertView
                .findViewById(R.id.status);
        status.setText(catList.get(position).getStatus());
         TextView id= (TextView) convertView
                .findViewById(R.id.id);
        id.setText(catList.get(position).getId));

        return convertView;

    }
4

1 に答える 1

1

あなたはほとんどそれを正しく理解しましたが、 convertView がリサイクルされている場合とそうでない場合の両方で、毎回設定する必要があります:

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.complete_order_row, parent,
                false);
       //...
    }
    TextView situation = (TextView) convertView
            .findViewById(R.id.situation);
    situation.setText(catList.get(position).getSituation());
    if (catList.get(position).getSituation().equals("notchecked")) {
       convertView.setBackgroundColor(Color.GREEN);
    } else {
       convertView.setBackgroundColor(Color.BLUE);
    }
于 2016-02-06T18:47:17.557 に答える