Android Question Sum of values from a listview

mico

Member
Licensed User
Longtime User
Dear all,

I have a problem with summing all values which are programmatically entered by the user in a listview.

The user enters the value in an EditText box, and when a button is pressed, the value is added to the list. This is repeated each time the button is pressed.

How can I get the sum of values entered to the list so far iteratively? Can you help me?

Thanks.

sum_list.png
 

DonManfred

Expert
Licensed User
Longtime User
How can I get the sum of values entered to the list so far iteratively?
Iterate through the list, get the value(s) and do math with them.

What have you tried so far?
Where is the projectupload which shows the issue?

Can you help me?
Are you expecting WE do the coding for you even if you just need to check the Documentation and the available Methods/Properties of a listview?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
If you enter with
B4X:
ListView1.AddSingleLine(EditText1.Text)

Can do it
B4X:
Dim V as int = 0
For i=0 to ListView1.Size-1
V=V+ListView1.GetItem(i)
Next

Log(V)

@DonManfred is right, you don't have to expect others to code for you
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
However you can also add the Value in a global variable as you add the Value in list within the Button Click event
 
Upvote 0

mico

Member
Licensed User
Longtime User
If you enter with
B4X:
ListView1.AddSingleLine(EditText1.Text)

Can do it
B4X:
Dim V as int = 0
For i=0 to ListView1.Size-1
V=V+ListView1.GetItem(i)
Next

Log(V)

@DonManfred is right, you don't have to expect others to code for you

Thank you very much. I was stuck in summing from the array actually, as:

B4X:
Sub btn_add_Click
Dim x_array(x_list.Size) As Float
Dim y_array(y_list.Size) As Float
For i=0 To x_list.Size-1
x_array(i)=x_list.GetItem(i)
Next
For j=0 To y_list.Size-1
y_array(j)=y_list.GetItem(j)
Next

I cannot get the sum of values in x_array, and y_array. I will try your help.

@DonManfred or else, I do not expect you do the coding for me, I can do it for me. Anyway, thanks again.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I was stuck in summing from the array actually, as:
You are NOT ADDING anything
For j=0 To y_list.Size-1
y_array(j)=y_list.GetItem(j)
Next
You are setting the array value to the itemvalue. In each iteration. There is no summing there.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
@DonManfred or else, I do not expect you do the coding for me, I can do it for me. Anyway, thanks again.
I suggest with starting the coding by yourself instead of asking questions. At least you should have posted ALL relevant code which you tried but which does not works.

Do not expect any further help from me!
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Maybe you need to do this to get a sum
B4X:
Sub btn_add_Click
Dim sum_x As Float = 0
Dim sum_y As Float = 0
For i=0 To x_list.Size-1
sum_x=sum_x+x_list.GetItem(i)
Next
For j=0 To y_list.Size-1
sum_y=sum_y+y_list.GetItem(j)
Next

However it is a simple sum, I hope for you that you do not develop software as a profession :p
 
Last edited:
Upvote 0

mico

Member
Licensed User
Longtime User
@Star-Dust : Thank you for your kind help.

@DonManfred : Also thank you for your fast respond. However, you should be more polite when talking with people who you don't meet or know personally.

Regards.
 
Upvote 0
Top