My test app is based on the following example:
www.b4x.com
What I'm trying to achieve: When a title item is clicked, I want to get the title item index . For example, if I click title item "Title #BBB", I want to find out its index which is 11.
I added the following code to get the index of the clicked title item, which works most of the time.
When the first title, Ttitle #AAA, is clicked, the app crashes. Below is the log
Test app attached. I don't know how to fix the error. Any helps would be appreciated greatly.
toby
[XUI] CustomListView with floating titles
Title items are added to the list. A Panel is set above the list. The panel shows the current title when the top visible item is not a title item. It works by checking for the top item type. If it is a title item then the panel is hidden, otherwise the panel is shown with the current title...
What I'm trying to achieve: When a title item is clicked, I want to get the title item index . For example, if I click title item "Title #BBB", I want to find out its index which is 11.
I added the following code to get the index of the clicked title item, which works most of the time.
B4X:
Sub lblTitle_Click
Dim index As Int = CLV1.GetItemFromView(Sender)
LogColor("clicked title item index=" & index, Colors.Green)
End Sub
When the first title, Ttitle #AAA, is clicked, the app crashes. Below is the log
entering lblTitle_Click
Error occurred on line: 420 (CustomListView)
java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:70)
at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:167)
at b4a.example3.customlistview._getitemfromview(customlistview.java:768)
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:5656)
at android.view.View$PerformClick.run(View.java:22462)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:6146)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Test app attached. I don't know how to fix the error. Any helps would be appreciated greatly.
toby
Attachments
Last edited: