Italian [Risolto] B4xPage con libreria Amir

Lello1964

Well-Known Member
Licensed User
Longtime User
Non ho mai usato B4XPage, devo utilizzare la libreria Amir.



ho questo codice :

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Public nomeAzienda As String
    Public idAzienda As String
    Public F As function
    Private ListCategory As List
    Private ListProduct As List
    Private Recycler As Amir_RecyclerView
    Private Carousel As Amir_RVCarousel
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    ListCategory.Initialize
    ListProduct.Initialize
    Root = Root1
    Root.LoadLayout("MainPageOrdina")
    ProgressDialogShow("Caricamento...")
    Wait For (F.chargeListCategoryStrictMode(idAzienda)) Complete(l As List)
        If l == Null Then
            Log("Errore di connessione nel database")
            ProgressDialogHide()
            B4XPages.ClosePage(Me)
        Else If l.Size == 0 Then
            Log("Nessuna Categoria nel database")
            ProgressDialogHide()
            B4XPages.ClosePage(Me)
        Else
            ListCategory = l
            ProgressDialogHide()
        End If
    Recycler.Initializer("Amir")
    Root.AddView(Recycler, 0, 0, 100%x, 100%y)
 
    Dim Carousel As Amir_RVCarousel
    Carousel.Initialize(Recycler)
    Carousel.Rotate = True
    Carousel.Orientation = Carousel.HORIZONTAL
    Carousel.Gravity = Carousel.GRAVITY_START
    Carousel.PeekDistance = 100dip
    Carousel.Radius = 1000dip
 
    Dim Adapter As Amir_RVAdapter
    Adapter.Initialize("Amir", Adapter.LOOP_FULL)
    Recycler.Adapter = Adapter
    Recycler.LinearSnapHelper
    Recycler.Color = Colors.White
End Sub

Private Sub Amir_onCreateViewFolder (Parent As Panel, ViewType As Int)
    Dim Label As Label
    Label.Initialize("")
    Parent.AddView(Label, 50%x-30dip, 0, 60dip, 60dip)
    Label.Padding = Array As Int(8dip, 8dip, 8dip, 8dip)
End Sub

Private Sub Amir_onBindViewHolder (Parent As Panel, Position As Int)
    Dim Label As Label = Parent.GetView(0)
    Label.TextColor = Colors.White
    Label.TextSize = 22
    Label.Gravity = Gravity.CENTER
    Label.Text = (Position+1)
    Dim Color As ColorDrawable
    Color.Initialize(0xFF005D80, 1000dip)
    Label.Background = Color
    Parent.Height = 68dip
End Sub

Private Sub Amir_GetItemCount As Int
    Return ListCategory.Size
End Sub

mi da questo errore :

Error occurred on line: 64 (B4XOrderPage)
java.lang.RuntimeException: Object should first be initialized (View).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at b4a.example.b4xorderpage._amir_onbindviewholder(b4xorderpage.java:89)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at com.aghajari.rv.Amir_RVAdapter$Amir_RVAdapterWrapper.onBindViewHolder(Amir_RVAdapter.java:164)
at com.aghajari.rv.Amir_RVAdapter$Amir_RVLoopTwoAdapterWrapper.onBindViewHolder(Amir_RVAdapter.java:367)
at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
at com.aghajari.layout.TurnLayoutManager.onLayoutChildren(TurnLayoutManager.java:187)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
at android.view.View.layout(View.java:20960)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:60)
at android.view.View.layout(View.java:20960)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:60)
at android.view.View.layout(View.java:20960)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:20960)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1842)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1686)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1595)
at android.view.View.layout(View.java:20960)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:926)
at android.view.View.layout(View.java:20960)
at android.view.ViewGroup.layout(ViewGroup.java:6279)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3037)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2545)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1636)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7946)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092)
at android.view.Choreographer.doCallbacks(Choreographer.java:893)
at android.view.Choreographer.doFrame(Choreographer.java:812)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078)
at a
Message longer than Log limit (4000). Message was truncated.
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**


Sos
 

Star-Dust

Expert
Licensed User
Non ci sono cambiamenti per l'uso B4XPage rispetto a un app tradizionale, visto che devi usarlo solo per b4a.

Sembra che qualche vista non è inizializzata ma viene usata. Sarebbe meglio vedere la parte di codice che solleva l'errore
 

LucaMs

Expert
Licensed User
Longtime User
Error occurred on line: 64 (B4XOrderPage)
java.lang.RuntimeException: Object should first be initialized (View).
Dim Label As Label = Parent.GetView(0) ' RIGA 64 "INCRIMINATA"
Non puoi dare ad una Label il nome... Label, che è un tipo!

Evitate SEMPRE di dare nomi... senza senso alle variabili! (e non mi riferisco a questo caso ma più in generale).
 

Lello1964

Well-Known Member
Licensed User
Longtime User
Non puoi dare ad una Label il nome... Label, che è un tipo!

Evitate SEMPRE di dare nomi... senza senso alle variabili! (e non mi riferisco a questo caso ma più in generale).
Ok, non lo avevo visto, non ho scritto io il codice, è quello del demo di Amir, però non funziona ugualmente.
 

Lello1964

Well-Known Member
Licensed User
Longtime User
ecco il progetto. manca solo la libreria
 

Attachments

  • pagamicoClient.zip
    16.1 KB · Views: 81

LucaMs

Expert
Licensed User
Longtime User
Scusa ma ci sarebbe da studiare almeno un'altra ora (seguendo le istruzioni nel thread della libreria, che non ho letto).

Vedo questo:

1610241265693.png


Sono gli esempi forniti e il tuo Recycler.Initializer("Amir") forse richiede anche quelle altre parti.

Inoltre, giusto per indirizzarti, l'errore in quella riga; il Parent pare essere di tipo Activity (quindi la Main Activity) mentre per funzionare con B4XPages dovrebbe essere Root.
 

Lello1964

Well-Known Member
Licensed User
Longtime User
Questo è l'esempio senza B4xPages che funziona benissimo da cui siamo partiti.

Main:
Sub Process_Globals

End Sub

Sub Globals
    Dim Recycler As Amir_RecyclerView

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Recycler.Initializer("Amir")
    Activity.AddView(Recycler,0,0,100%x,100%y)

    Dim Carousel As Amir_RVCarousel
    Carousel.Initialize(Recycler)
    Carousel.Rotate=False
    Carousel.Orientation=Carousel.VERTICAL
    Carousel.Gravity=Carousel.GRAVITY_START
    Carousel.PeekDistance=100dip
    Carousel.Radius=1000dip
    
    Dim Adapter As Amir_RVAdapter
    Adapter.Initialize("Amir",Adapter.LOOP_FULL)
    Recycler.Adapter=Adapter
    Recycler.LinearSnapHelper
    Recycler.Color=Colors.White
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Private Sub Amir_onCreateViewHolder (Parent As Panel,ViewType As Int)
    Dim Label As Label
    Label.Initialize("")
    Parent.AddView(Label,50%x-30dip,0,60dip,60dip)
    Label.Padding=Array As Int(8dip,8dip,8dip,8dip)
End Sub
Private Sub Amir_onBindViewHolder (Parent As Panel,Position As Int)
    Dim Label As Label=Parent.GetView(0)
    Label.TextColor=Colors.White
    Label.TextSize=22
    Label.Gravity=Gravity.CENTER
    Label.Text=(Position+1)
    Dim Color As ColorDrawable
    Color.Initialize(0xFF005D80,1000dip)
    Label.Background=Color
    Parent.Height=68dip
End Sub
Private Sub Amir_GetItemCount As Int
    Return 15
End Sub
 

Lello1964

Well-Known Member
Licensed User
Longtime User
Risolto,

usando

B4X:
    Recycler.Initializer("Recycler").NoLayout
    Root.AddView(Recycler,0,0,100%x,100%y)
    
    Dim CarouselVP As Amir_RVCarouselViewPager
    CarouselVP.Initializer("carousel",Recycler).MaxVisibleItemCount(5) _
    .ItemSpace(120dip).Horizontal.Build
    CarouselVP.CenterSnapHelper
    CarouselVP.Infinite=True
    
    Dim Adapter As Amir_RVAdapter
    Adapter.Initialize("carousel",Adapter.LOOP_NEVER)
    Recycler.Adapter=Adapter
 

Lello1964

Well-Known Member
Licensed User
Longtime User
Risolto anche il progetto originale :

B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Public nomeAzienda As String
    Public idAzienda As String
    Public F As function
    Private ListCategory As List
    Private ListProduct As List
    'Private Recycler As Amir_RecyclerView
    Private Carousel As Amir_RVCarousel
    Private Recycler As Amir_RecyclerView
    Public Data As Map
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    ListCategory.Initialize
    ListProduct.Initialize
    Root = Root1
    'Root.LoadLayout("MainPageOrdina")
    ProgressDialogShow("Caricamento...")
    Wait For (F.chargeListCategoryStrictMode(idAzienda)) Complete(l As List)
    If l == Null Then
        Log("Errore di connessione nel database")
        ProgressDialogHide()
        B4XPages.ClosePage(Me)
    Else If l.Size == 0 Then
        Log("Nessuna Categoria nel database")
        ProgressDialogHide()
        B4XPages.ClosePage(Me)
    Else
        ListCategory = l
        ProgressDialogHide()
    End If
        
    Recycler.Initializer("carousel").NoLayout
    Root.AddView(Recycler,0,0,100%x,100%y)

    Dim Carousel As Amir_RVCarousel
    Carousel.Initialize(Recycler)
    Carousel.Rotate=False
    Carousel.Orientation=Carousel.VERTICAL
    Carousel.Gravity=Carousel.GRAVITY_START
    Carousel.PeekDistance=100dip
    Carousel.Radius=1000dip
    
    Dim Adapter As Amir_RVAdapter
    Adapter.Initialize("carousel",Adapter.LOOP_FULL)
    Recycler.Adapter=Adapter
    Recycler.LinearSnapHelper
    Recycler.Color=Colors.White   

End Sub

Private Sub carousel_onCreateViewHolder (Parent As Panel,ViewType As Int)
    Dim Label As Label
    Label.Initialize("")
    Parent.AddView(Label,50%x-30dip,0,60dip,60dip)
    Label.Padding=Array As Int(8dip,8dip,8dip,8dip)
End Sub

Private Sub carousel_onBindViewHolder (Parent As Panel,Position As Int)
    Dim Label As Label=Parent.GetView(0)
    Label.TextColor=Colors.White
    Label.TextSize=22
    Label.Gravity=Gravity.CENTER
    Label.Text=(Position+1)
    Dim Color As ColorDrawable
    Color.Initialize(0xFF005D80,1000dip)
    Label.Background=Color
    Parent.Height=68dip
End Sub

Private Sub carousel_GetItemCount As Int
    Return 10
End Sub
 
Top