0

I want to get total of amount in a textview as shown below.

enter image description here

  // List of Amount
  for(t=0;t<pname.length;t++) {
      newRow = (TableRow) new TableRow(this);
      float val1= Float.parseFloat(price);
      float val2= Float.parseFloat(rate);
      String resultamount = Float.toString(val2- val1);
      Double value1 = Double.parseDouble(resultamount);

      ilist[a]=(TextView) new TextView(this);
      ilist[a].setText(String.format("%.2f", value1));  
  }

I have created another tablerow outside of for loop to get the total value.
I am now confused how to get the total from the list.
I tried but I am getting the last value of the list as total.

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
ləːnə
  • 323
  • 2
  • 8
  • 22

2 Answers2

0

First change

String resultamount = Float.toString(val2- val1);
Double value1 = Double.parseDouble(resultamount);

To

double value1 = (double)(val2- val1);

It has nothing to do with the answer it just strange code...

To access it outside the list, make it class member, or static, or any other way that will allow you to access it.

Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
0

you have not passed the layoutParam for the new TextView. You are setting the value in the TextView object.

See this for dynamic addition of textview

Currently, your textview is unknown about the textview. You need to tell your layout that you want to add new textview to it.

Community
  • 1
  • 1
Gaurav Gupta
  • 4,586
  • 4
  • 39
  • 72
  • Hi i have textview added to the layout and that is working well. My question here is how to get the list of amount value – ləːnə Dec 31 '13 at 13:18