shizzle31 shizzle31 - 2 months ago 13
Android Question

Android ListView count numbers

I've a question, how can i get the total count of items that are in a

ListView
. You can put many numbers in it (example: 1,20€ , 2,20€...).
And how I can get the total count and set it in to a
TextView
.
The numbers where added from a edittext.toString(without the €).

@Override
public void onClick(View v) {
String list_view_count_text = new_order_count.getText().toString();
String list_view_price_text = new_order_price.getText().toString();
if(TextUtils.isEmpty(list_view_count_text)){
Toast.makeText(getApplicationContext(),"Bitte gebe eine Anzahl ein!", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(list_view_price_text)){
Toast.makeText(getApplicationContext(),"Bitte gebe einen Preis ein!", Toast.LENGTH_SHORT).show();
return;
}
list_view_order_list.add(0, spinner_new_order_subitem.getSelectedItem().toString());
list_view_order_adapter.notifyDataSetChanged();

list_view_count_list.add(0, list_view_count_text);
list_view_price_adapter.notifyDataSetChanged();

list_view_price_list.add(0, list_view_price_text);
list_view_count_adapter.notifyDataSetChanged();
newOrderDialog.hide();

}
});


and after this it should new calculate.

Merry Christmas and thank you :)

Answer

To get the total sum of list_view_price_list try this

int sum;
for( int i = 0; i < list_view_price_list.size(); i++ )
{
    String price = mListViewLocation.getItemAtPosition(i).toString();
    price.substring(1); //to remove  €
    sum += Integer.parseInt( price );
}