and it's woriking fine...but what I can't do is to sum all that spPrice values in the Listview to get a Total of all that items
I've been working by adding all items to a list in order sum all later but I can't get (I don't know how to do it) each spPrice item
I just get the spName values not spPrice values
I've done a Sub that sum all that item but that executes itself on the spPrice_ItemClick and working fine but I know I need a "function" out that event because when I remove items I need that sum items left.
by default, the first line of a 2-line list view item is returned when you click on that item.
this is what you are experiencing. You could reverse lines 1 and 2 and show the price first,
but that might look strange.
There is another option: have you tried LV1.AddTwoLines2( spName.SelectedItem,SpPrice.SelectedItem, SpPrice.Price???)
what happens in this case is when you click on the item, that 3rd parameter is returned. i don't know
exactly what SpPrice is (a custom type?). i would image you keep its price somewhere. that price
is what you want to put as the 3rd parameter to LV1.AddTwoLines2(). is that understood?
if you show lbltotal on every item click, it will show a running sum of prices. You could also keep
a global variable with a running sum of prices.
Well you're saying SpPrice.Price.. but spPrice is a spinner it doesn't have that method. I have a button where I'll put a function that sum all without clicking anywhere in the listview.
spPrice.SelectedItem is a double value. and that is added to the listview (when I click on the spName). Once I added all product I wish I should press the button to execute a "function" that sum all items added in the listview I hope it can be understood what I need my english is too bad.
The fact that you are populating a listview implies that you have a source of the items names and prices, perhaps a SQLite database table, a text file, a list, a map, etc. Why can't you sum them before you add them to the listview. If that is doable in your situation, that is the easier way to do. Even if you are selecting a certain number of items that meet a certain criteria and filter, you can apply it to the source.
The fact that you are populating a listview implies that you have a source of the items names and prices, perhaps a SQLite database table, a text file, a list, a map, etc. Why can't you sum them before you add them to the listview. If that is doable in your situation, that is the easier way to do. Even if you are selecting a certain number of items that meet a certain criteria and filter, you can apply it to the source.
Hey Mahares my source is sqlite and first I fill the spPrice with a basic function then the Lv is filled by clicking that spinner. The spPrice click event has a method that sum in each click and that is what I don't want. I just want fill the Lv then with another function outside that click event (for example a button click) to sum each item in the LV.
It is really a waste of time to use and discuss ListView.
You should add the price as the value and calculate it with:
B4X:
CLV.Add(CreateItem(Name, Price), Price)
Sub Sum as Double
Dim Total As Double
For i = 0 To CLV.Size - 1
Total = Total + CLV.GetValue(i)
Next
Return Total
End Sub
ListView / CLV are UI elements. The role of UI elements is to show something to the user. It is always a better design not to confuse the data store with the visual representation. This provides much more flexibility.
With that said, getting the data from the list is also simple.
It is really a waste of time to use and discuss ListView.
You should add the price as the value and calculate it with:
B4X:
CLV.Add(CreateItem(Name, Price), Price)
Sub Sum as Double
Dim Total As Double
For i = 0 To CLV.Size - 1
Total = Total + CLV.GetValue(i)
Next
Return Total
End Sub
Sub SumValues
Private Total As Double
For i=0 To lv1.Size-1
Total=Total+lv1.GetItem(i)
Next
lbltotal.Visible = True
lbltotal.Text = "Monto Total $: "&Total
End Sub
Sub SumValues
Private Total As Double
For i=0 To lv1.Size-1
Total=Total+lv1.GetItem(i)
Next
lbltotal.Visible = True
lbltotal.Text = "Monto Total $: "&Total
End Sub