Android Question Ultra List View behaviour changes when using CellLongClick

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

I added this sub routine and the behaviour of the ultra list view changed. Instead of having a selection display on the screen after tapping on the list and staying there, it displays then immediately disappears.

Did I miss something?

B4X:
Sub ULV_CellLongClick(RowID As Long, CellIndex As Byte, Position As Int, ClickedPanel As Panel)
'   
'    ' Show the user an hourglass while everything loads.
'    '------------------------------------------------------------
'    Activity.LoadLayout("PleaseWait")
'
'    PanelPleaseWait.Visible = True
'       
'    DoEvents
'    DoEvents
'
'    StartActivity(PresetDetails)
End Sub

I commented out the coding just to make sure the coding was not causing the problem.
 

Informatix

Expert
Licensed User
Longtime User
Hi Everyone,

I added this sub routine and the behaviour of the ultra list view changed. Instead of having a selection display on the screen after tapping on the list and staying there, it displays then immediately disappears.

Did I miss something?

B4X:
Sub ULV_CellLongClick(RowID As Long, CellIndex As Byte, Position As Int, ClickedPanel As Panel)
'
'    ' Show the user an hourglass while everything loads.
'    '------------------------------------------------------------
'    Activity.LoadLayout("PleaseWait")
'
'    PanelPleaseWait.Visible = True
'    
'    DoEvents
'    DoEvents
'
'    StartActivity(PresetDetails)
End Sub

I commented out the coding just to make sure the coding was not causing the problem.
I suppose that you're talking of UltimateListView.
Without the rest of your code, nothing can be said. The sub in itself does not explain anything. I need at least the Filler sub and the CellClick sub if there's one.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi,

Yes, it's the UltimateListView.

Here's the code that sets it up:

B4X:
Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("Presets")

    kvPresetsList.Initialize(File.DirDefaultExternal, "kvPresetsList", 1)

    ' Add an ULV to the activity.
    '----------------------------
    ULV.Initialize(0, 0, "", "ULV")

    ' Set ULV properties.
    '--------------------
    ULV.Color = Colors.White
    ULV.SetStyle(ULV.STYLE_HOLO_LIGHT)
   
    ' Put the ULV view onto the current Activity.
    '--------------------------------------------
    Activity.AddView(ULV, 0, 0, 100%x, Activity.Height - 100dip)

    ' Change the pressed drawable of the ULV
    ' (the background of the clicked item will be green)
    '---------------------------------------------------
    Dim cd As ColorDrawable
    cd.Initialize(Colors.Green, 16dip)
    ULV.PressedDrawable = cd
    ULV.SetPadding(5dip, 5dip, 5dip, 5dip)

    ' Create a layout to display ULV.
    '--------------------------------
    ULV.AddLayout("Presets", "Item_LayoutCreator", "Item_ContentFiller", UlvItemHeight, True)
'    ULV.AddRowLayout("Presets", "Item_RowLayoutCreator", "Item_RowContentFiller",  _
'        UlvItemHeight, Widths.Length, Widths, DividerWidth, Colors.Gray, True)

    ' Build the items list for the ULV.
    '----------------------------------
    ULV.BulkAddItems(Main.intTotalPresetsSaved, "Presets", 0)       

    ULV.SelectionMode = ULV.SELECTION_SINGLE
End Sub

B4X:
Sub Item_RowLayoutCreator(LayoutName As String, CellPanel As Panel, CellIndex As Byte)
   
    'The layout of the data cells is very simple: just a label
    Dim lblText As Label
    lblText.Initialize("")
    lblText.Color = Colors.Transparent
    lblText.TextColor = Colors.Black
    lblText.TextSize = 16
    lblText.Typeface = Typeface.DEFAULT
    lblText.Gravity = Gravity.CENTER_VERTICAL
    CellPanel.AddView(lblText, 10dip, 5dip, CellPanel.Width - 20dip, CellPanel.Height - 10dip)
End Sub

B4X:
Sub Item_RowContentFiller(RowID As Long, LayoutName As String, CellPanel As Panel, CellIndex As Byte, Position As Int)

    Dim gdTheGradientDrawable As GradientDrawable
    Dim arrColours(2) As Int

    arrColours(0) = Colors.DarkGray
    arrColours(1) = Colors.Black

    gdTheGradientDrawable.Initialize("TOP_BOTTOM", arrColours)

    If ULV.IsSelected(Position) Then

        ' The selected rows are green.
        '-----------------------------
        CellPanel.Color = Colors.Green
    Else
        ' Set properties for the seperate lines that make up the list.
        '-------------------------------------------------------------
        CellPanel.Background = gdTheGradientDrawable
    End If

    ' Reads the data and sets the label text.
    '----------------------------------------
    Dim lbl As Label = CellPanel.GetView(0) 'The first (and only) view of the cell is a label
End Sub
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi,

Works nicely for the long click.

I tried to do the same for a cell click but the green highlight stayed on the previous cell I did a long click on and did not make it stay highlighted on the short click I did in another cell. When I short clicked a new cell the highlight flashed then it went back to the original black background colour.

Here's the code I used:

B4X:
Sub ULV_CellClick(RowID As Long, CellIndex As Byte, Position As Int, ClickedPanel As Panel)

        ULV.SetSelected(Position, Not(ULV.IsSelected(Position)))

End Sub
 
Upvote 0
Top