Android Question How to store multiple values in CustomListView value parameter?

Branko Milosevic

Active Member
Licensed User
I tried holding values in a custom type object array which does work but when CLV is resized and re-indexed my custom object array values are out of sync with CLV items.
 

Harris

Expert
Licensed User
Longtime User
Post some code...

I just started implementing CLV and find it works great - on all screen sizes in all situations.

I don't know if multiple params can be stored in the "value" (like a list or map).
Since it is a class, you should be able to do what you want it to do...
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
A simple help system when a user clicks on a row - that is NOT an input view...
This is a panel within the layout that will open or close depending on visibility and button press.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("sensmain")
   
    'clv1.AddTextItem(  "Set Idle Sensor (when GPS only)", "a")
    clv1.Add(  CreateListItem( $"ENABLE IDLE SENSOR (when GPS only)"$, clv1.AsView.Width, 90dip, 2),  90dip,   $"usesensor"$)
    clv1.Add(  CreateListItem( $"Idle Time Before Recording (seconds)"$, clv1.AsView.Width, 90dip, 1), 90dip,  $"idlerecord"$)
    clv1.Add(  CreateListItem( $"Idle Sensitivity"$, clv1.AsView.Width,   90dip,1), 90dip,  $"MagnitudeThreshold"$)
    clv1.Add(  CreateListItem( $"Idle Time Out (seconds)"$, clv1.AsView.Width,   90dip,1), 90dip,  $"stopIdle"$)
    clv1.Add(  CreateListItem( $"Drive Screen Dismiss Before Idle Count"$, clv1.AsView.Width,   90dip,3), 90dip,  $"drvdismiss"$)


    clv1.Add(  CreateListItem( $"ENABLE OBSTACLE WARNING"$, clv1.AsView.Width, 90dip, 2),  90dip,   $"warnenable"$)
    clv1.Add(  CreateListItem( $"Show Caution (Yellow) Warning When Within (x) meters"$, clv1.AsView.Width,   90dip,1), 90dip,  $"startwarn"$)
    clv1.Add(  CreateListItem( $"Show Extreme (Red) Warning When Within (x) meters"$, clv1.AsView.Width,   90dip,1), 90dip,  $"startextreme"$)
    clv1.Add(  CreateListItem( $"Enable Text To Speech Warning System"$, clv1.AsView.Width,   90dip,3), 90dip,  $"ttsenable"$)
    clv1.Add(  CreateListItem( $"Text To Speech Update Rate (seconds)"$, clv1.AsView.Width,   90dip,1), 90dip,  $"ttsrate"$)
    clv1.Add(  CreateListItem( $"Shorten Update Rate By Half When Extreme Warning"$, clv1.AsView.Width,   90dip,3), 90dip,  $"extremeenabled"$)


 '  If StateManager.RestoreState(Activity, "setsensors", 360) = False Then
        'set the default values
'        EditText1.Text = "Default text"
 '       EditText2.Text = "Default text"
  '  End If     
   btnSave.Background  = BDmod.CreateStateListDrawable
   btnClose.Background = BDmod.CreateStateListDrawable
   btnhelpclose.Background  = BDmod.CreateStateListDrawable
   pnlHelp.Visible = False
   Loadsettings  
   
End Sub

Sub clv1_ItemClick (Index As Int, Value As Object)
    Log(" item clicked: "&Index)
  
    Dim pnl As Panel = clv1.GetPanel(Index)
    Dim chk As Label = pnl.GetView(0)
    Dim str As String = chk.Text
    lblheader.Text = str
    lblhelp.Text = GetHelp(Value) ' CRLF&Value &"   index: "&Index  '.Title = Value&" edt value: "&edt.Text
    lblhelp.TextSize = BDmod.SetTextSize(lblhelp,lblhelp.Text,1)
    pnlHelp.Visible = True
    pnlHelp.BringToFront
End Sub

Sub GetHelp(val As Object) As String
  
    Dim seek As String = val
    Dim ret As String = "Sorry Folks, No Help Found For This Specific Topic. It May Be Obvious From The Title What Setting Is Required."
    Select seek
        ' idle detect section
        Case "usesensor"
        ret = "This setting will enable (turn on) or disable (turn off) the device / engine idle detection system. This uses the tablet or phone internal sensors to detect vibration.  If using an ECM Data Adaptor, this system is disabled (not required).  The following parameters will 'fine tune' this system."
        Case "idlerecord"
        ret = "This setting specifies the minimum number of seconds of continuous idle detection required before recording it as an idle event."
        Case "MagnitudeThreshold"
        ret = "This setting specifies the sensitivity of the vibration sensor (0.5 default).  The higher the number, the less sensitive idle detection becomes. Depending on the device (tablet or phone) and mounting location, more sensitivity may be required to detect vehicle vibration (when engine is running)."
        Case "stopIdle"
        ret = "This setting will RESET (to zero) accumulated idle time when vibration (engine running) is NOT detected after (x) seconds. This helps avoid recording fake / false idling time that was not produced by constant vibration - as when engine is actually running as opposed to tapping on the device to make entries (engine is off). "
        Case "drvdismiss"
        ret = "This setting (when enabled) will prevent detecting and recording idle time when the Driving Screen is being displayed."&CRLF&"When the vehicle comes to a stop, the Driving screen will stay in focus until 5 minutes have elapsed. After this time, or if touched, it will be dismissed to the MAIN form - where idle detection will begin again.   "
      
        ' warning section
           
        Case "warnenable"
        ret = "This setting will enable (turn on) or disable (turn off) obstacle detection warning.  This system warns operators of 'OBSTACLES' (culverts, signs, curbs, etc.) that they are approaching. This function uses the internal GPS device hardware and GPS markers (you recorded) that indicate where obstacles exist. Note: When Mode = 'Travel', Obstacle Warning is turned off (not required). The following parameters will 'fine tune' this system."

        Case "startwarn"
        ret = "This setting will determine, when approaching an ostacle, when to display (distance in meters) the Caution Warning message (Yellow)."&CRLF&"Example: "&CRLF&"   Slow Moving (Tractors/Mowers) - 50 meters"&CRLF&"   Medium Speed (50 kmh, Motor Graders) - 150 meters"&CRLF&"   Fast Moving (80 - 90 kmh, Snow Plows - 400 meters"

        Case "startextreme"
        ret = "This setting will determine, when approaching an ostacle, when to display (distance in meters) the Extreme Warning message (Red)."&CRLF&"Example: "&CRLF&"   Slow Moving (Tractors/Mowers) - 20 meters"&CRLF&"   Medium Speed (50 kmh, Motor Graders) - 100 meters"&CRLF&"   Fast Moving (80 - 90 kmh, Snow Plows - 150 meters"

        Case "ttsenable"
        ret = "This setting will allow the use of Text to Speech warnings. Along with the screen warning, The device will 'Speak' a warning as well. Pair your device to a bluetooth system (headset, car stereo or a bluetooth speaker) and get a louder audible warning when approaching obstacles."

        Case "ttsrate"
        ret = "This setting will define how often the Text to Speech message will be broadcast (in seconds) when approaching an obstacle. Set this based on how fast the vehicle generally travels."

        Case "extremeenabled"
        ret = "This setting, when enabled, will cut in half, the time required to broadcast the warning message when in the Extreme (Red) zone.  "

      
    End Select
  
    Return ret
  
End Sub
 
Upvote 0

Branko Milosevic

Active Member
Licensed User
You can put anything you like as the Value object. It can be a Map or List or a custom type (best option).
I made a custom type. So it's a custom type array but when I remove or add some items to the CLV the index of the CLV item changes and doesn't match any more with the index of the value object. For exemple:

Item(1) -> CustomTypeObject(1)
item(2) -> CustomTypeObject(2)
Item(3) -> CustonTypeObject(3)
......

After removing Item(2) we have re-indexed Items but not the custom type

Item(1) -> CustomTypeObject(1)
Item(2) -> CustomTypeObject(3)
.........


Then I tried to make a custom type of lists like this:

Type ThreeLists (list1 as list, List2 as List, List3 as List)

Dim TripleList as ThreeLists

TripleList.List1.Add("....")
TripleList.List2.Add("....")

And this wasn't working at all. Not with raf.writeB4XObject or any other list method wouldn't work on it.



I finally made my code work by making three separate lists outside of CLV and modify in-sync with CLV not using its value object. I save lists in a raf file at three locations


Utilizing CLV's value object would be preferable but I just couldn't find a way to make it work. A list is also singular item unless array of lists is used like i tried with the custom type but syncing would still be a problem.

A triple value parameter in CLV or a data object that can be put on the panel would be really helpful.

I am tempting to use three invisible labels on the panel as string data object. It would be inconvenient for saving it on file.
 
Last edited:
Upvote 0
Top