0

以下を使用してListViewにデータを入力します。

list = (ListView) findViewById(R.id.historylist);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
String[] titles = new String[]{"transactionID","date","description","redeem","reward","status"};

try{

for(int i=0;i<rows.length();i++){
    map = new HashMap<String, String>();
    for(int n=0;n<allRows.getJSONArray(i).length();n++){
        map.put(titles[n], allRows.getJSONArray(i).getString(n));
    }
    mylist.add(map);
}

mSchedule = new SimpleAdapter(
    History.this,
    mylist,
    R.layout.history_row,
    titles,
    new int[] {R.id.textView0, R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5});

list.setAdapter(mSchedule);

for(int i=0; i<mylist.size(); i++)
    if(((Map<String, String>) mSchedule.getItem(i)).get("status").equals("0"))
        try{
            // SET BACKGROUND COLOR OF ROW
        }catch(Exception e){
            Log.e("AAA Error getting ListView row", e.toString());
        }

}catch(Exception e){
Log.e("Error Creating ListView", e.toString());
}

ステータスが「0」のListView行の背景色を変更したいのですが。

何か案は?

NEW:更新されたコードは次のとおりです-はるかに優れています(JSONArrayから文字を手動で切り取らなければならない部分を除いて..eww ..)

private void showListView(JSONArray rows, JSONArray totals){

    list = (ListView) findViewById(android.R.id.list);
    ArrayList<String[]> rowValues = null;
    String[] r = null;

    try{
        rowValues = new ArrayList<String[]>();
        for (int i=0;i<rows.length();i++){

            r = rows.get(i).toString().replaceAll("\\[\"", "").replaceAll("\"\\]", "").split("\",\"");
            rowValues.add(r);
        }

        mba = new MyBaseAdapter(this, rowValues);
        list.setAdapter(mba);

    }catch(Exception e){
        Log.e("showListView() ERROR", e.toString());
    }
}
4

1 に答える 1

1

私はあなたができるとは思わない。あなたが言っていることを達成する唯一の方法は、BaseAdapter を拡張する新しいクラスを作成し、そのクラスの getView() メソッドでビューの背景色を変更することです

于 2012-04-23T01:33:17.970 に答える