1. Black Friday Sale - 50% off

    B4A Standard for $29 instead of $59!
    Buy Now
    Dismiss Notice

Android Code Snippet SD: Spinner with CustomView

Discussion in 'Code Snippets' started by Star-Dust, May 11, 2017.

  1. Star-Dust

    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
     
  2. Daniel Konstantinidis

    Daniel Konstantinidis New Member Licensed User

    The error came on Line 59 of the module SD_Spinner..
     
  3. Star-Dust

    Star-Dust Expert Licensed User

    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.
     
    Filippo and Johan Hormaza like this.
  4. Star-Dust

    Star-Dust Expert Licensed User

    Update, added method

    Enabled As Boolean
     
  5. Gabino A. de la Gala

    Gabino A. de la Gala Active Member Licensed User

    Hello. I have a problem.

    If I use:

    Code:
    Private Sub CreateClv1Item(item As ClvPedidosItem, Reg As MapAs B4XView
      
    Dim p As B4XView = xui.createPanel("")
      p.SetLayoutAnimated(
    000100%x115dip)
      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.
     
  6. Gabino A. de la Gala

    Gabino A. de la Gala Active Member Licensed User

    Breaks at:
    Code:
    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
     
  7. Star-Dust

    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:
    Code:
    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
    Code:
    Dim r As Reflector
    r.Target = r.GetActivityBA
    MyAct=r.GetField(
    "vg")
     
  8. Gabino A. de la Gala

    Gabino A. de la Gala Active Member Licensed User

    Perfect!!!

    Thank you very much.
     
  9. Gabino A. de la Gala

    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:

    Code:
    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: Jan 2, 2019
  10. Star-Dust

    Star-Dust Expert Licensed User

    I did not understand the question
     
  11. Gabino A. de la Gala

    Gabino A. de la Gala Active Member Licensed User

    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
     

    Attached Files:

  12. Star-Dust

    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)
    Code:
    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
    Code:
    SD_Spinner.GetBase.Top=myposTop
     
  13. Gabino A. de la Gala

    Gabino A. de la Gala Active Member Licensed User

    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

    Code:
    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
     

    Attached Files:

  14. Star-Dust

    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.

    Code:
    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
    Code:
    Dim Sp as SD_Spinner

    Panel.loadLayout("panelWithSpin")
    ' Coordinate Open Spin
    Sp.Top=10Dip
    Sp.Left=
    100Dip
     
  15. Gabino A. de la Gala

    Gabino A. de la Gala Active Member Licensed User

    Could be?

    Code:
    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.
     
  16. Star-Dust

    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
    Code:
    Private Top,Left As Int
    you have to change into
    Code:
    Public Top,Left As Int
     
  17. Gabino A. de la Gala

    Gabino A. de la Gala Active Member Licensed User

    I
    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.

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


    Private Sub CreateClv1Item(item As ClvPedidosItem, Reg As MapAs B4XView
        
    Dim p As B4XView = xui.createPanel("")
        p.SetLayoutAnimated(
    000100%x115dip)
        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
     
  18. Star-Dust

    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
     
  19. Gabino A. de la Gala

    Gabino A. de la Gala Active Member Licensed User

    This is a simplyfied example.¡

    I hope this helps.
     

    Attached Files:

  20. Star-Dust

    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: Jan 4, 2019
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice