简体   繁体   中英

How to add color to last item in ListView - Android?

here is my customer adapter code fragment.I get detail from Sqlite DB and my last row shows grand total of my report. I need to change its colour to green and how to implement it in Android .?

Adapter Calling point

salesReport = dbh.getMerchantWiseReport(epfNo,detOrsum,fromDate, toDate);
adapter = new TSRMerchantWiseReportAdapter(TSRReports.this, salesReport);
listView.setAdapter(adapter);

Please help me to sort out this issue Thanks

EDIT

Adapter class added here

public class TSRDateWiseReportAdapter extends BaseAdapter {

    Context context;
    ArrayList<SalesReport> salesReport;

    public TSRDateWiseReportAdapter(Context context, ArrayList<SalesReport> list) {
        this.context = context;
        salesReport = list;
    }

    public int getCount() {
        return salesReport.size();
    }

    public Object getItem(int position) {
        return salesReport.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup arg2) {
        SalesReport salesReportItems = salesReport.get(position);
        if (convertView==null){
            LayoutInflater inflater=(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
            convertView=inflater.inflate(R.layout.datewise_list_row,null );
        }

        String date=salesReportItems.getDate().toString();
        TextView tvDate = (TextView) convertView.findViewById(R.id.entered_date);
        if (date.equals("Grand Total")) {
            tvDate.setText("Grand Total");
        } else {
            try {
                SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
            Date d = sd.parse(date);
            sd = new SimpleDateFormat("yy/MM/dd");
            tvDate.setText(sd.format(d));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }



        TextView tvDenom = (TextView) convertView.findViewById(R.id.denom);
        tvDenom.setText(salesReportItems.getDenom().toString());
        TextView tvCardQty = (TextView) convertView.findViewById(R.id.card_qty);
        tvCardQty.setText(salesReportItems.getQty().toString());
        TextView tvAmount= (TextView) convertView.findViewById(R.id.amount);
        tvAmount.setText(salesReportItems.getAmount().toString());
        return convertView;
    }

}

add this into your getview of TSRDateWiseReportAdapter

if(position==salesReport.size()-1)
{
    convertView.setBackgroundColor(Color.parseColor("#00FF00"));
    //changing date color for last item in listview
    tvDate.setTextColor(Color.parseColor("#00FF00")); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM