Android Question CLV, row selection error

Mostez

Well-Known Member
Licensed User
Longtime User
I use this two subs to load items into CLV, every thing is OK, but when I click the row, sometimes toggles row selection, and sometimes it changes selection mode to multiple rows as shown in attached picture. I tried this example but also behaves the same. did I miss something?

B4X:
Sub ListNewItems()
   
    lstvNewWhat.Clear
   
    Dim rd As CLVrowData
    rd.Initialize
    Dim Ln As Int = 90dip
   
    rd.Description = "Create new or edit existing trip order."
    rd.RowTitle =  SysDeclare.NEW_INDEX_TRIP_ORDER
    rd.Icon = LoadBitmapResize(File.DirAssets,"order-icon.png",24dip,24dip,True)
    lstvNewWhat.add(CreateListItem(rd,False, lstvBrowseWhat.AsView.Width, Ln), SysDeclare.NEW_INDEX_TRIP_ORDER)
   
    rd.Description = "Add or update system list items."
    rd.RowTitle =  SysDeclare.NEW_INDEX_LIST
    rd.Icon = LoadBitmapResize(File.DirAssets,"list-icon.png",24dip,24dip,True)
    lstvNewWhat.add(CreateListItem(rd,False, lstvBrowseWhat.AsView.Width, Ln), SysDeclare.NEW_INDEX_LIST)
   
    rd.Description = "Create new or update existing shared contact."
    rd.RowTitle =  SysDeclare.NEW_INDEX_CONTACTS
    rd.Icon = LoadBitmapResize(File.DirAssets,"contacts-icon.png",24dip,24dip,True)
    lstvNewWhat.add(CreateListItem(rd,False, lstvBrowseWhat.AsView.Width, Ln), SysDeclare.NEW_INDEX_CONTACTS)
   
    rd.Description = "Update vehicles In\Out log."
    rd.RowTitle =  SysDeclare.NEW_INDEX_VEHICLES_LOGGER
    rd.Icon = LoadBitmapResize(File.DirAssets,"log-icon.png",24dip,24dip,True)
    lstvNewWhat.add(CreateListItem(rd,False, lstvBrowseWhat.AsView.Width, Ln), SysDeclare.NEW_INDEX_VEHICLES_LOGGER)

End Sub


Sub CreateListItem(RowData As CLVrowData,HideButton As Boolean, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    Activity.AddView(p, 0, 0, Width, Height)
    p.LoadLayout("CLVrow")
    p.RemoveView
   
    'imgRowIcon.Bitmap = RowData.Icon
    If Not (HideButton) Then imgRowIcon.Bitmap = RowData.Icon
    btnSelectRow.Visible = Not(HideButton)
    imgRowIcon.Visible = Not(HideButton)
   
    lblRowTitle.Text = RowData.RowTitle
    lblDescription.Text = RowData.Description
    Return p
End Sub

CLV selections code:

B4X:
Private CSelectionsNew As CLVSelections
    Private CSelectionsBrowse As CLVSelections
    Private XUI As XUI


B4X:
Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("home")

    tabHome.LoadLayout("newwhat", Chr(0xF115)  &  " New" )
    tabHome.LoadLayout("browsewhat", Chr(0xF1E5)  &  " View" )

    lstvBrowseWhat.DefaultTextBackgroundColor = XUI.Color_White
    lstvNewWhat.DefaultTextBackgroundColor = XUI.Color_White
    
    CSelectionsBrowse.Initialize(lstvBrowseWhat)
    CSelectionsNew.Initialize(lstvNewWhat)
    
    CSelectionsBrowse.Mode = CSelectionsBrowse.MODE_SINGLE_ITEM_TEMP
    CSelectionsNew.Mode = CSelectionsNew.MODE_SINGLE_ITEM_TEMP
    
    ListIBrowsetems
    ListNewItems

B4X:
Sub lstvNewWhat_ItemClick (Position As Int, Value As Object)
   
    Dim strVal As String = Value
    Dim CallActivity As Object
   
    CSelectionsNew.ItemClicked(Position)
    CSelectionsNew.Clear
.
.
....
 

Attachments

  • Screenshot_20210727-114700.png
    40.5 KB · Views: 177

Mostez

Well-Known Member
Licensed User
Longtime User
here what is happening, when I use StartActivity after CLV item click, the problem occurred, if I commented this
B4X:
StartActivity(CallActivity)
the CLV selection mode works OK, If I want to call activity, I had to wait until the selection color is faded out then call start activity, I don't know if it is the best solution, but it worked!

B4X:
Sub lstvNewWhat_ItemClick (Position As Int, Value As Object)
    
    Dim strVal As String = Value
    Dim CallActivity As Object
    CSelectionsNew.ItemClicked(Position)
    
    Select strVal
        Case SysDeclare.NEW_INDEX_TRIP_ORDER
            CallActivity = TripOrders
            
        Case SysDeclare.NEW_INDEX_LIST
            CallActivity = Lists

        Case SysDeclare.NEW_INDEX_VEHICLES_LOGGER
            CallActivity = VehiclesLogger
    
        Case SysDeclare.NEW_INDEX_CONTACTS
            CallActivity = Contacts
            
    End Select
    
    Sleep(300) 'wait until selection color is faded out
    StartActivity(CallActivity)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…