开发者

Need to get row coloured in listview based on conditional

I have fill the list view like this as given below

cursor = manifest_helper.GetDeliveriesAgainstManifest(pkManifest);
cursor.moveToFirst();

for (int i = 0; i < cursor.getCount(); i++) {

    map = new HashMap<String, String>();
    map.put("Deliv_Address",
            cursor.getString(cursor.getColumnIndex("Address")));
    map.put("Deliv_Time",
            cursor.getString(cursor.getColumnIndex("Time")));
    map.put("Deliv_Order",
            cursor.getString(cursor.getColumnIndex("DeliveryOrder")));
    map.put("Deliv_IsCustomerPickup",
            cursor.getString(cursor.getColumnIndex("IsCustomerPickup")));
    map.put("Deliv_FKDeliveryStatus",
            cursor.getString(cursor.getColumnIndex("FKDeliveryStatus")));
    map.put("Deliv_PKDelivery",
            cursor.getString(cursor.getColumnIndex("PKDelivery")));
    alist.add(map);
    cursor.moveToNext();

}
sd = new SimpleAdapter(this, alist, R.layout.deliveries_list_row,
        new String[] { "Deliv_Address", "Deliv_Time",
                "Deliv_Order", "Deliv_IsCustomerPickup",
                "Deliv_FKDeliveryStatus", "Deliv_PKDelivery" },
        new int[] { R.id.tv_Deliv_Address, R.id.tv_Deliv_Time,
                R.id.tv_Deliv_Order,
                R.id.tv_Deliv_IsCustomerPickup,
                R.id.tv_Deliv_FKDeliveryStatus,
                R.id.tv_Deliv_PKDelivery });
//selectedAdapter = new SelectedAdapter(this, 0, alist);
//selectedAdapter.setNotifyOnChange(true);

List开发者_开发百科Deliveries.setAdapter(sd);

The problem is that the field Deliv_IsCustomerPickup have values C or O in each rows.

I want to differentiate each of C or O with different colors in row i.e. one C with have red color and the one with O need to have blue color


Use ViewBinder.setViewValue() to place your conditional in. From here you have full access to the list UI.

Some pseudo code for your setViewValue:

if(your_condition) {
   SomeLayout layout = (SomeLayout) view.getParent();
   layout.setBackground(...);
}
return false; // let the system put values in the View objects.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜