user6011162
user6011162

Reputation:

Sum on Listview Item in Android

I Have Listview That Display in the Image. But now I Want to Sum of Amount column Double Value And show in One TextView below the ListView. so how to perform this operation.

enter image description here

Adapter code :

 public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.simple_casehistory, null);
            holder = new ViewHolder();
            holder.qty = (TextView) convertView.findViewById(R.id.cqty);
            holder.rate = (TextView) convertView.findViewById(R.id.crate);
            holder.amount = (TextView) convertView.findViewById(R.id.camount);  

holder.qty.setText(dataItems.get(position).GetQtyName()); 

     holder.rate.setText(dataItems.get(position).GetRateName());
        holder.amount.setText(dataItems.get(position).GetAmountName());               


            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }


        return convertView;
    }
    static class ViewHolder{
        TextView qty;
        TextView rate;
        TextView amount;

    }

Upvotes: 0

Views: 6743

Answers (3)

Govinda P
Govinda P

Reputation: 3319

try this sample code:

public double getTotal(ArrayList<YourItem> list){

    double total=0.0;
    for(int i=0;i<list.size();i++){
        total=total+Double.parseDouble(list.get(i).getAmount());
    }
    return total;
}

Upvotes: 5

Roman
Roman

Reputation: 11

I think you can handler the Sum of Amount in adapter, and getCount() should be +1, and last item you can show the Sum of Amount. do you show some code for you about your question?

Upvotes: -1

Rathna Kumaran
Rathna Kumaran

Reputation: 113

How you are supplying values to the ListView?

if it is an Adapter .. like

listview.setAdapter(new customAdapter(context,qty[],rate[],total[])),

Then

textView.setText(string.valueOf(total[0]+total[1]))

Upvotes: -2

Related Questions