Android Question Trying to show/hide items on a CLV with floating titles

toby

Well-Known Member
Licensed User
Longtime User
The attached test app is based on the CustomListView with floating titles example with lazy loading applied. All appear to be working correctly. For demo purpose, the list is very short.

Now I want to incorporate the hide/show item code (mainly calling ResizeItem function) which has been tested on a regular CustomListView. In this test app. I try to hide all items containing text "2" and they are indeed hidden as expected. However, as shown in the attached screenshot, there is a space gap (which is a little taller than an item height) at the hidden item location. If I scroll the list up and down, the gap would increase. The CLV height and number of items remain unchanged all the times. Could someone kindly enough to tell me what I did wrong, please?


hidden item gap.jpg
 

Attachments

  • hidden item gap.zip
    11.5 KB · Views: 196

Mahares

Expert
Licensed User
Longtime User
there is a space gap (which is a little taller than an item height) at the hidden item location. If I scroll the list up and down, the gap would increase
I replaced:
B4X:
CLV1.ResizeItem(i, 0)
with:
B4X:
CLV1.RemoveAt(i)   'mahares
The space is reclaimed. I am not sure if this solves your ultimate problem. I am not too knowledgeable on xCLV to predict unwanted consequences by doing that, but it worked here. Also, when you have long lists, the scrolling becomes jerkey.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
B4X:
CLV1.RemoveAt(i)   'mahares
The space is reclaimed. I am not sure if this solves your ultimate problem. I am not too knowledgeable on xCLV to predict unwanted consequences by doing that, but it worked here. Also, when you have long lists, the scrolling becomes jerkey.
It will remove the item permanently, not suitable for my particular application.

My new solution is
1. Add a B4XFloatTextField
2. Move the code related to show/hide items from clv1_VisiableRangeChanged() to B4XFloatTextField_TextChanged().

It works so far, updated test app attached.
 

Attachments

  • clvFloatingTitle_LazyLoading_ShowHideItems.zip
    11.9 KB · Views: 193
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
Also, when you have long lists, the scrolling becomes jerkey.

Did you run it in release mode? I found it's much better in release mode than in debug mode. Although not as smooth as I want, good enough for now.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It works so far, updated test app attached.
Toby: I tried your new project with the B4XFloatTextField_TextChanged().. For 4 or 5 items list it is ok, Try it For i = 0 To 40, and then search for 3 for instance, you will see all kind of gaps and erratic display. Something is still not kosher.
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
I also noticed that it's not reliable and I'm looking for a different and better approach by pointing to the first matching item without hiding anything.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I'm looking for a different and better approach by pointing to the first matching item without hiding anything.
I can think of possibly 2 solutions that may solve your situation, unless you have already figured it out:
1. Option 1: Using a SQLite database for the data and use an edittext or B4XFloatTextField to enter your search string and based on the edtSearchBox_TextChanged (Old As String, New As String, filter the outoutput using the LIKE operator in SQLite: exple: LIKE '%${New}%' to search on either side of the columns data. Youcan still use xCLV to display the data.
2. Option 2; Go the route of B4XTable which has a built-in powerful search feature that can filter your output, but it is horizontally page based rather than vertically scrolled xCLV
 
Upvote 0

thinktank

Member
I also noticed that it's not reliable and I'm looking for a different and better approach by pointing to the first matching item without hiding anything.

Instead of hiding/unhiding CLV items, you may jump to found item using clv.ScrollToItem() like this;

B4X:
private pos as int = 0 'this is global variable to store found position of clv item, so that we may start searching again from the last found item to onwards...
Private srch as string        
private found as boolean = false

For i = pos To clv.Size - 1

        srch = clv.GetValue(i) ' this value is the same which you added while creating CLV Items...
        
            If srch.Contains(txtSearchTerm.Text) Then
                clv.ScrollToItem(i)
                found = True
                pos = i + 1
                Exit
            End If
Next
 
Upvote 0
Top