Android Question Sum of values from a listview

Discussion in 'Android Questions' started by mico, May 10, 2019.

  1. mico

    mico Member Licensed 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
     
  2. DonManfred

    DonManfred Expert Licensed User

    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?

    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?
     
    Star-Dust and MarcoRome like this.
  3. mico

    mico Member Licensed User

    Thanks.
     
  4. Star-Dust

    Star-Dust Expert Licensed User

    If you enter with
    Code:
    ListView1.AddSingleLine(EditText1.Text)
    Can do it
    Code:
    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
     
    mangojack and MarkusR like this.
  5. Star-Dust

    Star-Dust Expert Licensed User

    However you can also add the Value in a global variable as you add the Value in list within the Button Click event
     
  6. mico

    mico Member Licensed User

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

    Code:
    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.
     
  7. DonManfred

    DonManfred Expert Licensed User

    You are NOT ADDING anything
    You are setting the array value to the itemvalue. In each iteration. There is no summing there.
     
  8. DonManfred

    DonManfred Expert Licensed User

    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!
     
  9. Star-Dust

    Star-Dust Expert Licensed User

    Maybe you need to do this to get a sum
    Code:
    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: May 10, 2019
  10. mico

    mico Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice