简体   繁体   English

如何在ListView - Android中为最后一项添加颜色?

[英]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. 这是我的客户适配器代码片段。我从Sqlite DB获取详细信息,我的最后一行显示了我的报告的总计。 I need to change its colour to green and how to implement it in Android .? 我需要将其颜色更改为绿色以及如何在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 将其添加到TSRDateWiseReportAdapter的getview中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android如何在每个listvIew列表项上添加图标并更改文本颜色,背景颜色 - Android How to add icon on each listvIew list item and change the text color,Background color 如何在Android中更改ListView项目的颜色和文本颜色 - How to change Listview item color and textcolor in android 如何从Android中的ListView获取当前选定项目的背景色 - How to get Background Color of currently selected item from ListView in Android 如何使用 if 条件 Android 更改列表视图项目背景颜色 - How to change listview item background color using if condition Android 如何在onListItemClick方法上为Android上的ListView的选定项目着色 - How to color selected item of ListView on android at onListItemClick method 列表视图项中 TextView 的颜色自动更改 android - Color of TextView in listview item changes automatically android ListView OnClickItems 更改 Android 中的项目颜色 - ListView OnClickItems change item color in Android 如何在Android应用程序中的每个ListView项目文本之前添加图标? - How to add an icon before every ListView item text in an Android Application? 我如何将每个项目添加到 listview android - How can i add each item to listview android Android-如何从其他类动态添加ListView项 - Android - How to add ListView item dynamically from other class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM