Android Question CLV with floating titles: Trying to get index of clicked title item

toby

Well-Known Member
Licensed User
Longtime User
My test app is based on the following example:

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

  • CLVfloatingTitleTest.zip
    13.7 KB · Views: 135
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
I downloaded the updated example and added the given pnlTitle_Click() event code. Below are my test results:
1. Clicking "Title #AAA" always works, which is very good.
2. When two or more title items are shown, only the top one has effect.

I would like to know which of any visible titles is clicked, whether or not they're at the top position.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
It's only the floating titles I'm having problems with. I need to know which floating title has been clicked.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
I've found a way to deal with the issue. Inside the CLV_ItemClick event, I look for title items as shown below.

B4X:
    If CLV1.GetValue(Index) Is TitleData Then
        Dim td As TitleData = CLV1.GetValue(Index)
        'pnlTitle.GetView(0).Text = td.Title
        LogColor("td.title=" & td.Title, Colors.Green)
    Else
        LogColor("CLV1.GetValue(index)=" & CLV1.GetValue(Index) , Colors.Green)
    End If

That means I have to handle first floating title differently from the rest of them. Am I doing it correctly or there is a better way?
 
Upvote 0
Top