Android Code Snippet SD: Spinner with CustomView

Gabino A. de la Gala

Active Member
Licensed User
The problems are different.
The first that the SPINNERs are inside a CustomListView and therefore to calculate the position must know the position of the Y scroll.
Secondly, you have loaded all the SPINNERs with LoadLayout and with the same name SD_Spinner1 and therefore for him it is always the same spinner and he is moving it.

However, I study it above, but I have to change it strongly. As it is, it can not work
Could somehow be assigned the panel that you deploy with the options to the panel of the item clicked ?. Thus the positions would be relative to the item, not to of activity.
 

Star-Dust

Expert
Licensed User
The open spinner is hooked to the main activity so you can take full advantage of the screen. It can not be attached to an internal panel, otherwise the dimensions would be limited to the size of the panel.

Anyway in the afternoon I send you the correct code
 

Gabino A. de la Gala

Active Member
Licensed User

Star-Dust

Expert
Licensed User

Gabino A. de la Gala

Active Member
Licensed User
Thanks, but I know how I should do it. But I'm off-site and you have to wait for it to come back.

PS. PS.xCustomListView uses scrollview does not use customListView, they are different things.
I did not want to rush you in any way.
I will wait "anxious" for news of you.

A greeting.
 

Star-Dust

Expert
Licensed User
I have attached the example.
You can not use SD_Spinner inside a CustomListView because you can not predict the exact location and then I modified the code by replacing the customListView with a ScrollView.
I made some minor changes to the class so that it can be inserted into a scrollView.

Then I update the example in post#1.
 

Attachments

Last edited:

Gabino A. de la Gala

Active Member
Licensed User
I have attached the example.
You can not use SD_Spinner inside a CustomListView because you can not predict the exact location and then I modified the code by replacing the customListView with a ScrollView.
I made some minor changes to the class so that it can be inserted into a scrollView.

Then I update the example in post#1.
It works perfectly.. Thanks a lot

Could you say me how can I obtain the item of the scrollview where the
I have attached the example.
You can not use SD_Spinner inside a CustomListView because you can not predict the exact location and then I modified the code by replacing the customListView with a ScrollView.
I made some minor changes to the class so that it can be inserted into a scrollView.

Then I update the example in post#1.
thank you very much for your help. The spinner options are already correctly displayed.

Now, I haver a new problem. How can I get the data of the "item" corresponding to the SD_Spinner on which I selected one of the options?
In the correspondent event, "only" the number and value of the selected option come as parameters.

I'm trying like this, but I can not get it:
B4X:
sub SD_Spinner1_ItemClick (Position As Int, Value As String)
    Log(Position & " " & Value)
    Dim spinner As SD_Spinner = Sender
    ...
End Sub
 

Star-Dust

Expert
Licensed User
It works perfectly.. Thanks a lot

Could you say me how can I obtain the item of the scrollview where the


thank you very much for your help. The spinner options are already correctly displayed.

Now, I haver a new problem. How can I get the data of the "item" corresponding to the SD_Spinner on which I selected one of the options?
In the correspondent event, "only" the number and value of the selected option come as parameters.

I'm trying like this, but I can not get it:
B4X:
sub SD_Spinner1_ItemClick (Position As Int, Value As String)
    Log(Position & " " & Value)
    'Dim spinner As SD_Spinner = Sender
    Dim Item As String=SD_Spinner1.GetItem(Position)
    Dim HelpText as String =SD_Spinner1.GetHelpText(Position)
End Sub
 

Gabino A. de la Gala

Active Member
Licensed User
B4X:
sub SD_Spinner1_ItemClick (Position As Int, Value As String)
    Log(Position & " " & Value)
    'Dim spinner As SD_Spinner = Sender
    Dim Item As String=SD_Spinner1.GetItem(Position)
    Dim HelpText as String =SD_Spinner1.GetHelpText(Position)
End Sub
Hello again. Attached project where I have managed to work with the SD_Spinner and a CLV and to display the list of options according to the SD_Spinner selected at any time.
Maybe you find it interesting to optimize it and apply it to your code.
But I still needed the same thing I asked you in the previous post.
In addition to obtaining the option selected in the sd_spinner, I also needed to know in which of the items of the CLV the said SD_Spinner was located to act accordingly.
For this I have added a tag in each of the items in the list of each SD_Spinner and thus be able to do a GetItemTag (x).
If there was a simpler way to do it, I would appreciate it if you told me how.
A greeting.

I need the equivalent of:
B4X:
Sub Spinner1_ItemClick (Position As Int, Value As Object)
    Dim Index = CLV1.GetItemFromView(Sender) As Int
    Dim ItemAux = CLV1.GetValue(Index) As ClvPedidosItem
    Dim KeyToSQLUpdate = ItemAux.LblCliente.text As String
    ToastMessageShow("Option: " & Position & ". Key for SQL Update: " & KeyToSQLUpdate, True)
End Sub
And now I can do:
B4X:
Sub SD_Spinner1_ItemClick (Position As Int, Value As String)
    Log("SD_Spinner:" & Position & " " & Value)
    Dim SD_SpinnerAux = Sender As SD_Spinner
    Dim ItemAux = SD_SpinnerAux.GetItemTag(Position) As ClvPedidosItem
    Dim KeyToSQLUpdate = ItemAux.LblCliente.text As String
    ToastMessageShow("Option: " & Position & ". Key for SQL Update: " & KeyToSQLUpdate, True)
End Sub
 

Attachments

mahdi atashjam

New Member
Licensed User
Hello friends
I simply solved this problem

You will not have a problem even in scrollview

See line : 79 & 113



B4X:
private Sub DesignerList
    Dim HeightListView As Int = 0
    Dim Space As Int
   
    If ListItem.size>0 Then
        If AppPanel.IsInitialized Then AppPanel.RemoveView
        MyAct.addview(AppPanel,0,0,100%x,100%Y)
               
        If RoundCorner Then    ListPanel.Color=Colors.Transparent Else ListPanel.Color=BColorList
        ListPanel.RemoveView
        ListPanel.Panel.RemoveAllViews
        ListPanel.Panel.Height=0

        For i=0 To ListItem.Size-1
            Dim Item As Item
            Item.Initialize
           
            Item = ListItem.Get(i)
            Dim P As Panel
            P.Initialize("PanelClick")
            If RoundCorner Then P.Background=Corner(Item.BackgroundColor) Else P.Color=Item.BackgroundColor
           
            P.Tag=I
            Try
                Space=40dip
                Dim Ima As ImageView
                Ima.Initialize("")
                Ima.Gravity=Gravity.FILL
                If RoundCorner Then
                    Ima.SetBackgroundImage(RoundBorders(Item.Image,20dip))
                Else
                    Ima.SetBackgroundImage(Item.Image)
                End If
               
                P.AddView(Ima,0dip,5dip,40dip,40dip)
            Catch
                Space=0dip
            End Try
           
            Dim La As Label
            La.Initialize("")
            La.Text=Item.text
            La.TextSize=15
            La.Color=Colors.Transparent
            La.TextColor=Item.TextColor
            La.Typeface=Typeface.DEFAULT_BOLD
            La.Gravity=Item.G
           
            P.AddView(La,Space,0dip,mBase.Width-Space,30dip)
            If Item.texthelp.Trim<>"" Then
                Dim La As Label
                La.Initialize("")
                La.Text=Item.TextHelp
                La.TextSize=12
                La.Color=Colors.Transparent
                La.TextColor=Item.TextColor
                La.Gravity=Item.G
                P.AddView(La,Space,25dip,mBase.Width-Space,30dip)
            Else
                La.Height=50dip
            End If
            ListPanel.Panel.AddView(P,-mBase.Width,HeightListView,mBase.Width-2DIP,49dip)
            P.SetLayoutAnimated(10+(HeightListView/3),1dip,HeightListView,mBase.Width-2DIP,49dip)
            HeightListView=HeightListView+50dip
        Next
        ListPanel.Panel.Height=HeightListView
       
        Dim LeftSpinner,TopSpinner,HeightSpinner,Yafter As Int
       
        If GrayDisplay Then AppPanel.Color=Colors.aRGB(200,0,0,0) Else AppPanel.Color=Colors.Transparent
        If ScrollViewParent.IsInitialized Then
            If Left+mBase.Width+ScrollViewParent.Left>100%x Then LeftSpinner=100%x-mBase.Width Else LeftSpinner=Left
        Else
            If Left+mBase.Width>100%x Then LeftSpinner=100%x-mBase.Width Else LeftSpinner=Left
        End If
       
        Yafter=100%y-Top-mBase.Height
        If ScrollViewParent.IsInitialized Then
            baseTop=Top
            Yafter=Yafter+ScrollViewParent.ScrollPosition
            Top=Top-ScrollViewParent.ScrollPosition
        End If
        If (HeightListView>Top)And (HeightListView>Yafter) Then
            ' Non va bene dappertutto
            If (Top>100%y-Top-mBase.Height) Then
                'sopra é più grande
                TopSpinner=0dip
                HeightSpinner=Top
            Else
                'sotto è più grande
                TopSpinner=Top+mBase.Height
                HeightSpinner=100%y-Top-mBase.Height
            End If
        Else if (HeightListView>Top) And (HeightListView<=Yafter) Then
            ' Va bene di sotto
            TopSpinner=Top+mBase.Height
            HeightSpinner=HeightListView
        Else If (HeightListView<=Top)And (HeightListView>Yafter) Then
            ' Va bene di sopra
            TopSpinner=Top+mBase.Height-HeightListView
            HeightSpinner=HeightListView
        Else
            ' Haqspazio sopra e sotto
            TopSpinner=Top+mBase.Height
            HeightSpinner=HeightListView
        End If
       
        If ScrollViewParent.IsInitialized=False Then
            AppPanel.AddView(ListPanel,LeftSpinner,TopSpinner,mBase.Width,HeightSpinner)
        Else
            AppPanel.AddView(ListPanel,LeftSpinner,TopSpinner,mBase.Width,HeightSpinner)
        End If
        Top=baseTop
        'AppPanel.Visible=True
    End If
End Sub
 

Attachments

Star-Dust

Expert
Licensed User
This is a class of over 3 years ago so it is now outdated. It probably won't be updated, but you can make some changes if you want.

Magazine today would have been written differently and certainly using the XUI library to make it cross-platform.
 
Top