ListView for Settings

splatt

Active Member
Licensed User
Longtime User
I'm using a listview to control settings.

B4X:
lvSettings.AddTwoLines2("Standard Mode","Select Standard or Advanced Mode","GM")

When the user presses this Item, I want to change the text on the lable to "Advanced Mode" or "Standard Mode" to show which mode is currently in use.

What is the most efficient way to do this?
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Steve,
Please try something like this:

B4X:
Dim standard As Boolean
Dim mode as String

ListView1_ItemClick (Position As Int, Value As Object)
   standard = Not(standard)
   If standard Then mode = "Standard Mode" Else mode = "Advanced Mode"
   FillListView
End Sub

Sub FillListView
   lvSettings.AddTwoLines2(mode,"Select Standard or Advanced Mode","GM")
End Sub
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User
Alfcen, thanks for your reply. Perhaps I didn't explain myself properly.

I have created the list as above, but when the user clicks this listitem I want to toggle the label between "Standard Mode" and "Advanced Mode", thus setting the option.

I need to edit the selected list item text.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately you can not directly change an item label after having filled the ListView.
If you want to chage it you need to clear the whole list and fill it again.
You could try to use a ScrollView insted.

Several examples are in the forum.

Best regards.
 
Upvote 0

alfcen

Well-Known Member
Licensed User
Longtime User
Thanks a lot Klaus!

That's it, Steve, the new value will be shown by calling the Sub FillListView upon an Item Click.
Sorry, I failed to add "lvSettings.Clear". It was a rough sample, though.
This pattern works formidably in my apps.

Good luck!
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User
Thanks Klaus and Alfcen. I spent an hour last night trying different things and was begining to suspect that I couldn't edit them!

Redoing the listview is no big deal as there are only 7 items in it.

Thanks guys!
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User
Alfcen,

I call lvSettings.Clear, but nothing happens.

When I recreate the listview, it draws over the top of the original text, which looks rather odd!
 
Upvote 0

alfcen

Well-Known Member
Licensed User
Longtime User
Hi Steve, here is the complete code example snippet. Modifications may be required to suit your specific application.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim mode As String
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim standard As Boolean
   Dim lvSettings As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   lvSettings.Initialize("lvSettings")
   Activity.AddView(lvSettings,0,0,100%x,50%y)
   mode = "Advanced Mode"
   FillListView
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub lvSettings_ItemClick (Position As Int, Value As Object)
   standard = Not(standard)
   If standard Then mode = "Standard Mode" Else mode = "Advanced Mode"
   FillListView
End Sub

Sub FillListView
   lvSettings.Clear
   lvSettings.AddTwoLines2(mode,"Select Standard or Advanced Mode","GM")
End Sub
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User
Alfcen,

I call lvSettings.Clear, but nothing happens.

When I recreate the listview, it draws over the top of the original text, which looks rather odd!

I'd managed to initialise the list again! Sorted! Works well now. Thanks again for your help Alfcen.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…