Android Question How do I get a "List" to update DATA

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

Newbie dumb question/s,

I am attempting to use a list to store/retrieve numbers to/from a number of "Memories". I have been able to confirm that the "numbers" are being stored in the relevant "memories" but when I bring up the list next time it does not show the updated value.

Q1 How do I get the "list" to show the current value of Mem(1), not the value of Mem(1) when initialised.
Q2 Is the "ItemHeight" in List an adjustable property.

Additional: I tried using Listview as an alternative and after reading everything I can find (including the tutorial) I produced a view that sat in front of everything else and nothing worked.
Q3 Can someone please suggest a simple working program that uses Listview, I find examining code in context more productive than code examples in isolation.

Thanks in advance
Roger

Sub add_menu
storelist.Initialize
storelist.Add("M1 " & Mem(1))
storelist.Add("M2 " & Mem(2))
storelist.Add("M3 " & Mem(3))
storelist.Add("M4 " & Mem(4))
storelist.Add("M5 " & Mem(5))
storelist.Add("M6 " & Mem(6))
storelist.Add("M7 " & Mem(7))
storelist.Add("M8 " & Mem(8))
storelist.Add("M9 " & Mem(9))
storelist.Add("M10 " & Mem(10))
End Sub

Sub Store
Vibrate.Vibrate (50) ' Vibrate phone for 50 ms
Dim p As Int
p = InputList(storelist,"Stored Numbers",0)

Dim d1 As Double
If Not(F_common) Then Return
If disp(1) <> "" Then
d1 = disp(1)
Else
d1 = 0
End If

If p = 0 Then
Mem(1) = d1
Else If p = 1 Then
Mem(2) = d1
Else If p = 2 Then
Mem(3) = d1
Else If p = 3 Then
Mem(4) = d1
Else If p = 4 Then
Mem(5) = d1
Else If p = 5 Then
Mem(6) = d1
Else If p = 6 Then
Mem(7) = d1
Else If p = 7 Then
Mem(8) = d1
Else If p = 8 Then
Mem(9) = d1
Else If p = 9 Then
Mem(10) = d1
End If

lblShift.Text = "" ' Resets Shift mode to standard mode
shift_flag = 0
End Sub
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
B4X:
If p = 0 Then
Mem(1) = d1
'*10
This is equivalent to:
B4X:
Mem(p+1) = d1

Q1: You should use CustomListView class instead of ListView. It will allow you to change the items text.
Q2: Yes. See ListView tutorial: http://www.b4x.com/android/forum/threads/listview-tutorial.6537/#content


Erel
Thanks for the speedy reply but I am somewhat puzzled as your answers don't actually match the questions.

However I have found that I can achieve an updated display of the stored data by the following:
If p = 0 Then
Mem(1) = d1
storelist.Set(0,("M1= " & Mem(1)))
Else If p = 1 Then
Mem(2) = d1
storelist.Set(1,("M2= " & Mem(2))) ..... Etc

I will keep pushing ahead.

Regards Roger
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What Erel meant is :
instead of
B4X:
If p = 0 Then
    Mem(1) = d1
Else If p = 1 Then
    Mem(2) = d1
Else If p = 2 Then
    Mem(3) = d1
Else If p = 3 Then
    Mem(4) = d1
Else If p = 4 Then
    Mem(5) = d1
Else If p = 5 Then
    Mem(6) = d1
Else If p = 6 Then
    Mem(7) = d1
Else If p = 7 Then
    Mem(8) = d1
Else If p = 8 Then
    Mem(9) = d1
Else If p = 9 Then
    Mem(10) = d1
End If
use this
B4X:
Mem(p + 1) = d1

and with the code from your last post
B4X:
Mem(p + 1) = d1
storelist.Set(p,("M" & (p + 1) & "= " & Mem(p + 1)))
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
What Erel meant is :
instead of
B4X:
If p = 0 Then
    Mem(1) = d1
Else If p = 1 Then
    Mem(2) = d1
Else If p = 2 Then
    Mem(3) = d1
Else If p = 3 Then
    Mem(4) = d1
Else If p = 4 Then
    Mem(5) = d1
Else If p = 5 Then
    Mem(6) = d1
Else If p = 6 Then
    Mem(7) = d1
Else If p = 7 Then
    Mem(8) = d1
Else If p = 8 Then
    Mem(9) = d1
Else If p = 9 Then
    Mem(10) = d1
End If
use this
B4X:
Mem(p + 1) = d1


Thanks Klaus

I did understand the above code suggestion of Erels [a good one] and have since modified the code, which now reads better.
What puzzled me was that my question [Q1] was in relation to storing data via a list and and that new data value being displayed in the list. Erels reply was for me to use "CustomListView class instead of ListView" to allow me to "change the items text".
i Doesn't seem to match the question.
ii I had already stated I have failed at ListView after reading the tutorial suggested by Erel.

I guess I need to work on my communication skills.

Regards
Roger
 
Upvote 0
Top