Android Code Snippet SD: Spinner with CustomView

Star-Dust

Expert
Licensed User
Say you are assigning a type of type seen a value or a variable of other type. Check the line 59
 

Star-Dust

Expert
Licensed User
The error came on Line 59 of the module SD_Spinner..
It is not possible to understand what happens with the few inflamations that you give.
Debug and see which line the error presents.

Try starting from the attached example

PS. The class is made available with the source code so that every developer can modify it, improve it or correct it.
I do not offer assistance on classes with attached source because every developer is able to intervene directly on the source code and therefore no assistance is required.
 

Star-Dust

Expert
Licensed User
Update, added method

Enabled As Boolean
 

Gabino A. de la Gala

Active Member
Licensed User
Hello. I have a problem.

If I use:

B4X:
Private Sub CreateClv1Item(item As ClvPedidosItem, Reg As Map) As B4XView
  Dim p As B4XView = xui.createPanel("")
  p.SetLayoutAnimated(0, 0, 0, 100%x, 115dip)
  p.LoadLayout("ClvPedidosItem")
  ...
  ...
  ...
End Sub
To load individual items in a clv, then I get: java.lang.RuntimeException: Object should first be initialized (View) in the p.LoadLayout line.

If I use Activity.LoadLayout("main"), then the SD_Spinner works perfectly.

Any idea?

Thanks.
 

Gabino A. de la Gala

Active Member
Licensed User
Breaks at:
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")
        Log(Obj.Parent)
        Try
            Left=Left+Obj.Left
            Top=Top+Obj.Top
        Catch
            Log("Errore")
        End Try
        Obj=Obj.Parent
    Loop
    MyAct=Obj
...
End Sub
 

Star-Dust

Expert
Licensed User
It does not work because it is within a view that the parent does not find correctly, usually accessing the ScrollView panel.
Replace this:
B4X:
Dim Obj As View = mBase
    Do While Not(GetType(Obj) = "android.widget.FrameLayout")
        Log(Obj.Parent)
        Try
            Left=Left+Obj.Left
            Top=Top+Obj.Top
        Catch
            Log("Errore")
        End Try
        Obj=Obj.Parent
    Loop
    MyAct=Obj
with this
B4X:
Dim r As Reflector
r.Target = r.GetActivityBA
MyAct=r.GetField("vg")
 

Gabino A. de la Gala

Active Member
Licensed User
It does not work because it is within a view that the parent does not find correctly, usually accessing the ScrollView panel.
Replace this:
B4X:
Dim Obj As View = mBase
    Do While Not(GetType(Obj) = "android.widget.FrameLayout")
        Log(Obj.Parent)
        Try
            Left=Left+Obj.Left
            Top=Top+Obj.Top
        Catch
            Log("Errore")
        End Try
        Obj=Obj.Parent
    Loop
    MyAct=Obj
with this
B4X:
Dim r As Reflector
r.Target = r.GetActivityBA
MyAct=r.GetField("vg")
Perfect!!!

Thank you very much.
 

Gabino A. de la Gala

Active Member
Licensed User
How can I set the top of spinner options panel depending of the clv selected item?
The left works with next code:

B4X:
private Sub Lab_Click
    Dim I As IME
    I.Initialize("")
    I.HideKeyboard
    Dim labelaux As Label = Sender
    Dim panelaux As Panel = labelaux.Parent
    Left2 = panelaux.Left
    'Left2 = 100%x - panelaux.Width
    Top2 = panelaux.Top + panelaux.Height
    DesignerList
End Sub
 
Last edited:

Star-Dust

Expert
Licensed User
I did not understand the question
 

Gabino A. de la Gala

Active Member
Licensed User
I did not understand the question
I would like to get the panel with the possible options to be selected from the spinner to be correctly located underneath the SD_Spinner selected at all times as the standard Spinner does.
With the previous piece of code, I get it to be correctly positioned with respect to the horizontal position.
What I need now is to position it vertically depending on the item of the CustomListView in which the SD_Spinner is hosted.
Look at the attached image to see if this way I can explain myself better.
The value of Left2 and Top2 would apply later in the Sub DesignerList
 

Attachments

Star-Dust

Expert
Licensed User
As you will see in the original code there is the modification of two variables top and left.
That piece of code gives you the error needed to correctly position the spinner in the screen.
having eliminated you can still place it accidental top and left property from the outside and position it correctly.
(Make sure the variables are public and not private)
B4X:
SD_Spinner.Top=myposTop
This change does not change the position of the View but only of the Spinner. to change the position of the view, this would be
B4X:
SD_Spinner.GetBase.Top=myposTop
 

Gabino A. de la Gala

Active Member
Licensed User
As you will see in the original code there is the modification of two variables top and left.
That piece of code gives you the error needed to correctly position the spinner in the screen.
having eliminated you can still place it accidental top and left property from the outside and position it correctly.
(Make sure the variables are public and not private)
B4X:
SD_Spinner.Top=myposTop
This change does not change the position of the View but only of the Spinner. to change the position of the view, this would be
B4X:
SD_Spinner.GetBase.Top=myposTop
I'm sorry, but I do not understand what you mean.
If I leave the code as it comes from origin, the panel with the different options of the spinner places it in the same vertical position (not the correct one depending on the selected SD_Spinner) and also almost to the left of the whole of the screen.

Hence, I tried to solve it with two new variables that I only apply if necessary

B4X:
Sub DesignerList
...
' Variables para intentar colocar el ListPanel correctamente
        If Left2 <> 0 Then L = Left2
        If Top2 <> 0 Then T = Top2
        AppPanel.AddView(ListPanel,L,T,mBase.Width,h)
...
End Sub
 

Attachments

Star-Dust

Expert
Licensed User
It is not necessary for you to modify the library from within. But just change some properties of the spinning that I had already entered for this event.

B4X:
Dim Sp as SD_Spinner

Panel.AddView(Sp.GetBase,100dip,10dip,100dip,50dip)
' Coordinate Open Spin
Sp.Top=10Dip
Sp.Left=100Dip
If inserted into the Design
B4X:
Dim Sp as SD_Spinner

Panel.loadLayout("panelWithSpin")
' Coordinate Open Spin
Sp.Top=10Dip
Sp.Left=100Dip
 

Gabino A. de la Gala

Active Member
Licensed User
It is not necessary for you to modify the library from within. But just change some properties of the spinning that I had already entered for this event.

B4X:
Dim Sp as SD_Spinner

Panel.AddView(Sp.GetBase,100dip,10dip,100dip,50dip)
' Coordinate Open Spin
Sp.Top=10Dip
Sp.Left=100Dip
If inserted into the Design
B4X:
Dim Sp as SD_Spinner

Panel.loadLayout("panelWithSpin")
' Coordinate Open Spin
Sp.Top=10Dip
Sp.Left=100Dip
Could be?

B4X:
sp.GetBase.Top=10dip
sp.GetBase.Left=100dip
Top and left is unreachable in Update 1.0.1 28/09/2017 of SD_Spinner class.
 

Star-Dust

Expert
Licensed User
I already explained in post #52 that you do not have to do SD_Spinner1.GetBase.Top (and left).
Read carefully what I wrote to you.

At the beginning of the class you will find
B4X:
Private Top,Left As Int
you have to change into
B4X:
Public Top,Left As Int
 

Gabino A. de la Gala

Active Member
Licensed User
I already explained in post #52 that you do not have to do SD_Spinner1.GetBase.Top (and left).
Read carefully what I wrote to you.

At the beginning of the class you will find
B4X:
Private Top,Left As Int
you have to change into
B4X:
Public Top,Left As Int
I
I already explained in post #52 that you do not have to do SD_Spinner1.GetBase.Top (and left).
Read carefully what I wrote to you.

At the beginning of the class you will find
B4X:
Private Top,Left As Int
you have to change into
B4X:
Public Top,Left As Int
Thank you very much for your quick response.
I had already made that change to public.
After doing it I have managed to get the horizontal position correctly, but unfortunately, the vertical position does not adjust it well.
It remains at the top of the screen regardless of the spinner of the clv that you select.

B4X:
Sub FillData
            Dim ClvItem As ClvPedidosItem
            ClvItem.Initialize
            Clv1.Add(CreateClv1Item(ClvItem, Reg), ClvItem)
End Sub


Private Sub CreateClv1Item(item As ClvPedidosItem, Reg As Map) As B4XView
    Dim p As B4XView = xui.createPanel("")
    p.SetLayoutAnimated(0, 0, 0, 100%x, 115dip)
    p.LoadLayout("ClvPedidosItem")
    'p.LoadLayout("PruebaClvSD_Spinner")
    item.LblCliente = LblCliente
    item.LblFecha = LblFecha
    item.CheckBoxAplazado = CheckBoxAplazado
    item.SpinnerOpcionesClv1 = SpinnerOpcionesClv1
    item.SD_SpinnerOpcionesClv1 = SD_SpinnerOpcionesClv1
   
    LblCliente.Text     = "Cliente: " & Reg.Get("Cliente".ToLowerCase)
    LblFecha.Text         = Reg.Get("Fecha".ToLowerCase)
    LblFiscal.Text         = Reg.Get("RazonFiscal".ToLowerCase)
    LblComercial.Text     = Reg.Get("RazonComercial".ToLowerCase)
    LblNApuntes.Text    = Reg.Get("NApuntes".ToLowerCase)
    CheckBoxAplazado.Checked = Reg.Get("Estado".ToLowerCase) = "A"
    CheckBoxAplazado.Enabled = False
   
   
    SD_SpinnerOpcionesClv1.Top=10dip
    SD_SpinnerOpcionesClv1.Left=100dip
    SD_SpinnerOpcionesClv1.Add("Op1","Non so1 lo que tu esperabas", 1,Colors.Black,Colors.White,Gravity.CENTER,Null)
    SD_SpinnerOpcionesClv1.Add("Op2","Non so2", 2,Colors.Black,Colors.White,Gravity.CENTER,Null)
    'SD_SpinnerOpcionesClv1.Left2 = SD_SpinnerOpcionesClv1.GetBase.Left
    SpinnerOpcionesClv1.Add("Opciones:")
    If CheckBoxAplazado.Checked Then
        SpinnerOpcionesClv1.Add("Activar")
    Else
        SpinnerOpcionesClv1.Add("Aplazar")
    End If
    SpinnerOpcionesClv1.Add("Cambiar Fecha")
    SpinnerOpcionesClv1.Add("Cancelar")
    SpinnerOpcionesClv1.SelectedIndex = -1
   
    SpinnerOpcionesClv1.DropdownBackgroundColor = Colors.Green
    SpinnerOpcionesClv1.DropdownTextColor = Colors.Magenta
    SpinnerOpcionesClv1.TextColor = Colors.Red
   
       
    Return p
End Sub
 

Star-Dust

Expert
Licensed User
I do not understand the problem well. SD_Spinner is inside a panel or inside what?

I would like to understand all the parents of the spinner until you get to Activity
 

Star-Dust

Expert
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
 
Last edited:
Top