Spinner doesnt show the data

mrjaw

Active Member
Licensed User
Longtime User
Hi!
I am filling a few spinner with data from my MS-SQL server. I bring the data using a WS until here everything is fine but when I try to show the spinner I get nothing


B4X:
   Rec=Regex.Split("@",Tbl(0)) '
        spLinea.Add("Lines")
   For i=0 To Rec.Length-1
      spLinea.Add(Rec(i))
   Next

This code is into a function and I declare all spinners in Global section

I checked that Rec had elements using log but in my layout the data doesnt be shown

I am using a Kindle Fire for testting

Any cluees?
 

mrjaw

Active Member
Licensed User
Longtime User
This is one example. Doesnt work neither.

I am using Kindle Fire with 1024x600 density 1
 

Attachments

  • spinner.zip
    6.8 KB · Views: 230
Upvote 0

mrjaw

Active Member
Licensed User
Longtime User
When I dont initialize so I get this error
B4X:
sistema_activity_create (B4A line: 45)
Return taskCounter
java.lang.RuntimeException: Object should first be initialized (Spinner).
   at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:45)
   at anywheresoftware.b4a.objects.SpinnerWrapper.Add(SpinnerWrapper.java:100)
   at b4a.example.sistema._activity_create(sistema.java:279)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at b4a.example.sistema.afterFirstLayout(sistema.java:84)
   at b4a.example.sistema.access$100(sistema.java:16)
   at b4a.example.sistema$WaitForLayout.run(sistema.java:72)
   at android.os.Handler.handleCallback(Handler.java:605)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4486)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Object should first be initialized (Spinner).

Really I dont know when I use or not.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I guess that you are doing it on your original code and not the sample you posted, if you remove the initialization lines on the SAMPLE (spinner.zip) it works.

You will have to post your actual project to see what's the problem.
 
Upvote 0

mrjaw

Active Member
Licensed User
Longtime User
This is so big but I post the main activity

B4X:
'Activity module
Sub Process_Globals

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim tabhost1 As TabHost
   Dim PanelMenu As Panel
   Dim spLote,spOrden,spLinea,spUbicacion,spTipo,spOrigen,spDefecto As Spinner
   Dim Sx As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   '
   If FirstTime Then
'      spLinea.Initialize("")
'      spLote.Initialize("")
'      spOrden.Initialize("")
'      spUbicacion.Initialize("")
'      spTipo.Initialize("")
'      spOrigen.Initialize("")
'      spDefecto.Initialize("")
   End If
   '

   
   Dim url As String
   url=libcode.CreateUrl("2#" & Main.Prefer.IDcon)
   '
   Log("Url:" & url)
   '
   Dim jobA  As HttpJob
   jobA.Initialize("jobA", Me)
   jobA.Download(url)
   '
   PanelMenu.Initialize("")
   Activity.LoadLayout("menu")
   Activity.Title=Main.Titulo
   '
   'Sx.Initialize("")
   Sx.Add("Uno")
   Sx.Add("Dos")
   Sx.Add("Tres")
   '
   'tabhost1.AddTab("Datos Generales", "datosgenerales") 
   'tabhost1.AddTab("Defectos Encontrados", "defectosencontrados")

End Sub


'Ejecucion de los Webservices
Sub JobDone (Job As HttpJob)
   Dim res As String
   '
   If Job.Success = True Then
      res = Job.GetString      
      res= libcode.DesEncriptarCadena(res)
      Log("res::" & res)
      '
      Select Job.JobName
          Case "jobA"   'cargando todos los combos del sistema
            InitSPData(res)    
            
         End Select
   End If
   Job.Release
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub InitSPData(resu As String)
   Dim Tbl() As String
   Dim Rec() As String
   '
   Tbl=Regex.Split("&",resu) 'Rompiendo tablas
   '   
   'lineas de produccion   
   Rec=Regex.Split("@",Tbl(0)) '
   spLinea.Add("Lineas")
   For i=0 To Rec.Length-1
      spLinea.Add(Rec(i))
      Log("Linea "& i & Rec(i))
   Next
   '
   'Lotes   
   Rec=Regex.Split("@",Tbl(1)) '
   spLote.Add("Lotes")
   For i=0 To Rec.Length-1
      spLote.Add(Rec(i))
      Log("Lotes " & i & Rec(i))
   Next
   '
   'Ordenes Produccion
   spOrden.Add("Ordenes")
   Rec=Regex.Split("@",Tbl(2)) '
   For i=0 To Rec.Length-1
      spOrden.Add(Rec(i))
   Next
   '
   'Ubicaciones
   spUbicacion.Add("Ubicaciones")
   Rec=Regex.Split("@",Tbl(3)) '
   For i=0 To Rec.Length-1
      spUbicacion.Add(Rec(i))
   Next
   '
   'Especifcaciones defecto
   spDefecto.Add("Especificaciones-Defecto")
   Rec=Regex.Split("@",Tbl(4)) 
   For i=0 To Rec.Length-1
      spDefecto.Add(Rec(i))
   Next
   '
   'Origen Defecto
   spOrigen.Add("Origen Defecto")
   Rec=Regex.Split("@",Tbl(5)) 
   For i=0 To Rec.Length-1
      spOrigen.Add(Rec(i))
   Next
   '
   'Tipo Muestro
   spTipo.Add("Tipo Muestreo")
   Rec=Regex.Split("@",Tbl(6)) 
   For i=0 To Rec.Length-1
      spTipo.Add(Rec(i))
   Next
End Sub

'Seleccionando la captura de muestra
Sub bmenu3_Click
   
   '
   Msgbox(spLinea.GetItem(0),"Error")
   
   PanelMenu.Visible=False
   Activity.LoadLayout("datosgenerales")
   '
End Sub

En function Sub bmenu3_Click I call the layout where are the spinners
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
These are the problems I'm seeing so far:

1- You are initializing the spinners in If FirstTime, that's wrong, doing it that way it will ONLY initialize them the VERY FIRST TIME your app runs.

2- I see you create a panel (PanelMenu) in code and also you load a layout (Activity.LoadLayout("menu")), where is PanelMenu added to the Activity? is PanelMenu part of the "menu" layout?

You should keep things the same, meaning, if you are creating views with the designer then use just the designer, creating some views with the designer and others in code might be confusing.

I hope that helps you understand some of your problems.
 
Upvote 0
Top