Android Code Snippet SD: Spinner with CustomView

I've created a new class with CistomView to have the same features on the spinner object as ListView. A second line of text and the ability to add an image beside each item.

Also there is the ability to put the screen in gray when you click on the spinner. And finally, the ability to represent each item with rounded edges. In the cases there is an image that will also be rounded.

Hope it may be useful to you

Proprietes
Enabled As Boolean
SelectedItem As String
SelectedID As String
SelectedIndex As String
GrayDisplay As Boolean ' If Make Screeen gray when click (Set/Get)
BColor As Int ' BackgroundColor of Spinner's Label (Get/Set)
TColor As Int ' TextColor of Spinner's Label (Get/Set)
HintColor As Int ' TextColor of Spinner's Hint (Get/Set)
RoundCorner As Boolean
If the spinner opens in an anomalous position:
Set these prorpietes (left e Top) to set the screen position of the spinner's aperture on the screen.
For this reason we do not recommend inserting the spinner inside a scrollView because it has problems calculating its opening, or setting the position from code using left and top

Left As Int
Top As Int

Method
Initialize (vCallback As Object, vEventName As String)
Add(Text As String, TextHelp As String,ID As String, BackgroundColor As Int, TextColor As Int, Gravities As Int,Image As Bitmap)
' Add Single element
AddAll(L As List, TextHelp As String, BackgroundColor As Int, TextColor As Int, Gravities As Int)
' Add a List
Size as int ' return number of elements
Clear ' Clear all elements
RemoveIndex(Position As Int) ' Remove element at Index
RemoveID(ID As String) ' Remove element from ID
GetItem(Position As Int) As String ' Get Value from position/index
GetItemFromID(ID As String) As String ' Get Value from ID
GetID(Position As Int) As String ' Get ID at position/index
SetIndex(Position As Int) ' Set selected from position/index
SetID(Id As String) ' Set selected from ID
SetBackgroundDrawable(Draw As ColorDrawable) ' Set Background with colordrawable
SetBackgroundImage(Bitmap As Bitmap) ' Set Background with image
SetLabelTextSize(TextSizeLabel As Int) ' Set Text Size of label
Close ' close a ListItem windows
Open ' Apen a ListItem Windows​

Event
ItemClick (Position As Int, Value as String)​

Update 1.02
Screen1.png Screen2.png Screen3.png Screen4.png Screen5.png Screen6.png
 

Attachments

  • SD_Spinner 1.02.zip
    19.7 KB · Views: 1,171
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Add a Little animation
 

Star-Dust

Expert
Licensed User
Longtime User
Non ho capito
_________________________________________________________
I do not understand. Please write in English
 
Last edited:

luciano deri

Active Member
Licensed User
Longtime User
In genere negli spinner, dopo che hai selezionato dalla lista, il contenuto della cella selezionata viene mostrato nello spinner chiuso a sinistra della freccia. Nell'esempio che ho scaricato il riquadro dello spinner rimane sempre vuoto.
 

Star-Dust

Expert
Licensed User
Longtime User
Ho verificato e non mi da questo errore. In ogni caso nel prossimo Post manderò un aggiornamento della classe, fammi sapere se hai lo stesso problema
_______________________________________________________________
I checked and I did not make this mistake. Anyway in the next post I'll send an update to the class, let me know if you have the same problem
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Update class
 

Star-Dust

Expert
Licensed User
Longtime User
I have to see the code, the error says it is not initialized
 

Star-Dust

Expert
Licensed User
Longtime User
I already solved the error, what happened was that I was loading it with a Panel.loadlayout, and that did not work. Thanks in advance.
By the way, this bookstore is great, my brother.
Thank's
 

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
I have the Spinner in one position, but the panel that is displayed appears in another position.
What would be the problem?
Thank you
 

Star-Dust

Expert
Licensed User
Longtime User
Sometimes if there are too many nested panels it can not find the absolute position.

On spinner you will find two porprieties that allow to correct this problem: Spinner.Left and Spinner.Top.

After you have hooked the Spinner in a panel, Assign Spinner.left and Spinner.Top the position you want it to appear on the screen and everything resolves.
 

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Is this sub true?
B4X:
Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
        mBase = Base
        mBase.Tag="SD_SPINNER"
    
        Left = 0
        Top = 0
        Dim Obj As View = mBase
        Do While Not(GetType(Obj) = "android.widget.FrameLayout")
            Try
                Left = Left + Obj.Left
                Top =Top + Obj.Top
            Catch
                Log(".")
            End Try
            Obj = Obj.Parent
        Loop
        MyAct=Obj
    
        If Props.ContainsKey("BackgroundColor") Then BColor = Props.Get("BackgroundColor")
        If Props.ContainsKey("BackgroundColorList") Then BColorList=Props.Get("BackgroundColorList")
        If Props.ContainsKey("TextColor") Then TColor = Props.Get("TextColor")
        If Props.ContainsKey("TextSize") Then TextSize = Props.Get("TextSize")
        If Props.ContainsKey("HintColor") Then HintColor = Props.Get("HintColor")
        If Props.ContainsKey("GrayDisplay") Then GrayDisplay = Props.Get("GrayDisplay")
        If Props.ContainsKey("RoundCorner") Then RoundCorner = Props.Get("RoundCorner")
    
        Lab.TextColor = TColor
    Lab.Color = 0xFFE2E2E2
        Lab.Typeface = Typeface.DEFAULT_BOLD
        Lab.Gravity = Gravity.CENTER
        Lab.Gravity = Gravity.CENTER_VERTICAL
        Lab.TextSize = TextSize
        Lab.BringToFront
        Lab.Text = "Pot. Luminaria"
        SetIndex(SelectedIndex)
    mBase.Color = 0xFFE2E2E2
        mBase.AddView(Lab,13%x,0,mBase.Width,mBase.Height)
        mBase.AddView(img,3dip,2dip,12%x,mBase.Height - 4dip)
 

Star-Dust

Expert
Licensed User
Longtime User
I'm not sure I understand what you're asking
 
Top