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


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: 160
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…