iamRaja iamRaja - 6 months ago 63
Android Question

how to get all values of particular TextView of listView? -Android

i have made ListView with three columns 'item','qty','rate' i get this entries from the user and i have made the listview work perfectly but i want to get all the values of the 'rate' column and add them for the net amount.

Here is my android code:

protected void onCreate(Bundle savedInstanceState) {
adapter = new listviewAdapter(List.this, list);

private void populateList() {
HashMap temp = new HashMap();
list = new ArrayList<HashMap>();

item = etItem.getText().toString();
qty = etQty.getText().toString();
rate = etRate.getText().toString();

temp.put(FIRST_COLUMN, "1");
temp.put(SECOND_COLUMN, item);
temp.put(THIRD_COLUMN, qty);
temp.put(FOURTH_COLUMN, rate);


I tried out this method below but it only toast the first value.But i want to get all the values under the rate column and add them up for the net-amount.

public void get() {
StringBuilder sb = new StringBuilder();
for(int i=0; i<adapter.getCount(); i++) {
String a = ((TextView) findViewById(R.id.FourthText)).getText().toString();
text = sb.toString();
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show();


I think this might help you.

private int GrandTotal(ListView list) {
int sum=0;
for (int i = 0; i < list.getCount(); i++) {
    View v = list.getChildAt(i);
    TextView rate = (TextView) v.findViewById(R.id.rate);
    sum = sum + Integer.parseInt(rate.getText().toString() )
return sum;