Using Preferences with a Listview
Hi,
thanks for the info. I have opted to use the a standard solution using a listview.
For those interested, some code snippets - the app including source (current beta)
here (Note: readme in German BUT code commented in English.
Sub Globals
' Listview holding the settings
Dim lvSettings As ListView
' Row 1 = setting
' Row 2 = brief description
' Listview entry data
Type ListViewDataS (FirstRow As String, SecondRow As String, ID As String)
' Define the setting entries shown in the listview
' Listview Row1 = icon , key; Row2 = hint
Dim CSETTINGSCNT As Int : CSETTINGSCNT = 4
Dim CSETTINGSKEY() As String = Array As String("Help", "About", "Actions", "Preferences")
Dim CSETTINGSHINT() As String = Array As String("Help Hint", "About Hint", "Actions Hint", "Settings Hint")
Dim CSETTINGSICON() As String = Array As String("ic_help.png", "ic_info.png", "ic_event.png", "ic_settings.png")
...
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Settings")
...
' Load data into the listview from the arrays
lvSettings_Load
End Sub
Sub lvSettings_Load
' Build the settings listview = per entry bitmap, firstline and secondline
Dim tface As Typeface
tface = Typeface.CreateNew(Typeface.SERIF, Typeface.STYLE_NORMAL)
lvSettings.Clear
lvSettings.TwoLinesAndBitmap.SecondLabel.TextSize = 16
lvSettings.TwoLinesAndBitmap.SecondLabel.Typeface = tface
For i = 0 To CSETTINGSCNT - 1
Dim lvdd As ListViewDataS
lvdd.Initialize
lvdd.FirstRow = CSETTINGSKEY(i)
lvdd.SecondRow = CSETTINGSHINT(i)
lvdd.ID = i
lvSettings.AddTwoLinesAndBitmap2(lvdd.FirstRow, lvdd.SecondRow, LoadBitmap(File.DirAssets, CSETTINGSICON(i)), lvdd)
Next
End Sub
Sub lvSettings_ItemClick (Position As Int, Value As Object)
' Clicked on a listview item = the setting is being called according the value of the object = lvdd.ID
Dim lvdd As ListViewDataS
' Get the data
lvdd = Value
' Act on the selected value
Select lvdd.ID
Case 0 ' Help
Msgbox(Main.CHELPINF, Main.CHELPHDG)
Case 1 ' About
Msgbox("About...", "")
Case 2 ' Manage activties
Activity.Finish
StartActivity("Activities")
Case 3 ' Various settings using the standard preferences
StartActivity(Main.prefScreen.CreateIntent)
End Select
' Utils.logApp("Listview item clicked. ID = " & lvdd.ID)
End Sub
Thank You,
Rob