Android Question xcustomlistview- error

Discussion in 'Android Questions' started by kisoft, Apr 20, 2019.

  1. kisoft

    kisoft Active Member Licensed User

    HI
    I'm using xcustomlistview in this way.
    Code:
    Sub Globals
        
    Private index As Int
        
    Private CustomListView1 As CustomListView
        
    Private button1 As Button
    End Sub


    Sub CreateListItem(Width As Int, Height As Int) As Panel
        
    Dim p As Panel
        p.Initialize(
    "")
        
    Activity.AddView(p, 00, Width, Height)
        p.LoadLayout(
    "cust2")
        p.RemoveView
        
    Return p
    End Sub

    Sub Button1_Click()
        index=CustomListView1.GetItemFromView(
    Sender)
        
    Log(index)
        modl
    End Sub

    Sub modl
        
    Select index
                    
    Case 0
                wid.a=
    0
                            
    CallSub(widok,"wte")

                
    StartActivity(wid)
            
    Case 1
                
    StartActivity(dk)
            
    Case 2
                            
    Log(index)
            
    Case 3
    when index = 2 I get this error:
    Code:
    *** Service (starter) Create ***
    ** 
    Service (starter) Start **
    ** 
    Activity (main) Create, isFirst = true **
    ** 
    Activity (main) Resume **
    Error occurred on line: 
    93 (Main)
    java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast 
    to android.view.View
        at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:
    69)
        at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:
    166)
        at b4a.example3.customlistview._getitemfromview(customlistview.java:
    408)
        at modlitewnik.gk2.main._button1_click(main.java:
    551)
        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.raiseEvent2(BA.java:
    180)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    176)
        at anywheresoftware.b4a.objects.ViewWrapper$
    1.onClick(ViewWrapper.java:80)
        at android.view.View.performClick(
    View.java:6274)
        at android.view.View$PerformClick.run(
    View.java:24859)
        at android.os.Handler.handleCallback(Handler.java:
    789)
        at android.os.Handler.dispatchMessage(Handler.java:
    98)
        at android.os.Looper.loop(Looper.java:
    164)
        at android.app.ActivityThread.main(ActivityThread.java:
    6710)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:
    240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    770)
    Line 93 is the code:
    Code:
    index=CustomListView1.GetItemFromView(Sender)
    Previously, everything worked well, the problem arose when I upgraded the SDK.
    I am using B4A 9.0
     
  2. kisoft

    kisoft Active Member Licensed User

    Error detected. A big brothel in the code ... that's the reason for this error.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    This is not needed if you are using a recent version of B4A:
    Code:
    Dim p As Panel
        p.Initialize(
    "")
        
    Activity.AddView(p, 00, Width, Height)
        p.LoadLayout(
    "cust2")
        p.RemoveView
    Instead:
    Code:
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(
    000, Width, Height)
    p.LoadLayout(
    "cust2")
     
  4. kisoft

    kisoft Active Member Licensed User

    OK... thank you
     
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