Android Question Is it possible to add a divider to a spinner?

Sandman

Expert
Licensed User
Longtime User
Hi all,

I have a spinner with a list of items. At a certain position I'd like to have a divider. (Please note, this does not mean a divider between every item in the spinner, just a single divider at a single position.) I can't find an obvious way to do this, and searching the forum didn't really turn up anything. I'm guessing it's not possible and I should find another solution, or?

I found this question on Stack Overflow that discusses this, with the possible difference for me is that I have a spinner, not a menu. https://stackoverflow.com/questions/33277124/how-to-add-dividers-between-specific-menu-items

This probably isn't a spinner, but it kind of shows what I'm looking for:

7Pz3Q.png
 

Sandman

Expert
Licensed User
Longtime User
You can use the SD_Spinner library

Thanks, that seems like a nice custom spinner, but it doesn't work for me as it becomes extremely sluggish when I add 250 items. (Not an option to change it to some other UI element, it's a list of countries.) It takes on average 4.5 seconds to just open the spinner when the user taps it. I optimized the code quite a bit and got it down to about 2.5 seconds, which still isn't responsive enough. I'm using a Nexus 5X with 7.1.2.

(I timed this in the DesignerList sub. Turns out it's the last ListPanel.Panel.AddView eating up most of the time - I don't know how to optimize that.)

I was more hoping that I simply could find a method like Spinner1.addDivider that I had missed. Or getting the same result by some Java Object wizardry, perhaps. Do you know if something like that is posssible?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
For ListView exists as you see in this explanation. Unfortunately it is in Java.
https://cyrilmottier.com/2011/07/05/listview-tips-tricks-2-section-your-listview/
and
https://stackoverflow.com/questions/18302494/how-to-add-section-separators-dividers-to-a-listview

I did not find anything for Spinner, but I would do something like that
B4X:
Dim ListView1 As ListView

    ListView1.Initialize("ListView1")
    'For item
    ListView1.Color=Colors.White
    ListView1.TwoLinesLayout.Label.Color=Colors.White
    ListView1.TwoLinesLayout.Label.TextColor=Colors.Black
    ListView1.TwoLinesLayout.Label.Typeface=Typeface.DEFAULT_BOLD
    ListView1.TwoLinesLayout.SecondLabel.Color=Colors.White
    ListView1.TwoLinesLayout.SecondLabel.TextColor=Colors.Black
    ' For separator line
    ListView1.SingleLineLayout.label.color=Colors.Blue
    ListView1.SingleLineLayout.label.TextColor=Colors.Blue
    ListView1.SingleLineLayout.ItemHeight=10dip

    Activity.AddView(ListView1,0,0,200dip,100%y)
    For i=0 To 10
        If i=5 Then
            'separator
            ListView1.AddSingleLine2(i,"LineSeparator")
            Else
            ' Item
            ListView1.AddTwoLines2("Number " & i,"Info",I)
            End If
    Next
End Sub

Sub ListView1_ItemClick (Position As Int, Value As Object)
    If Value="LineSeparator" Then
        'ignore it
        ToastMessageShow("Separator ",False)
    Else
        ' Item Selected
        ToastMessageShow("Item " & Value,False)
    End If
End Sub
1.png
 
Last edited:
Upvote 0
Top