Android Question Automatic Scroll Listview to certain position

cirollo

Active Member
Licensed User
Longtime User
Hi guys!

I have 50 items in the listview and click the item nr.35 (it could be the 2nd or 3rd or 4th record on the screen).
I made my modifications as in the item_click event, then I would like the selected item to be in the same position as before, not at the first position (is already done this way)....

so, on the screen:

xxxxx
xxxxx
xxxxx <--- my item
xxxxx
.......
xxxxx

after item_click event (and associated calculations), I must still have:

xxxxx
xxxxx
xxxxx <--- my item
xxxxx
.......
xxxxx

and not....

xxxxx <--- my item
xxxxx
.......
xxxxx


is possible?
 

DonManfred

Expert
Licensed User
Longtime User
Maybe listview.SetSelection('index') might work for this.
You should read post #1 carefully.
Using your code the listview will try to place the selected index at the first visible position. That´s not what he want
 
Upvote 0

Tyler

Member
Licensed User
Longtime User
Sorry, I should have elaborated. Not sure if this will work 100% but if he were to setselection to the index 2 above that one for example, would that not place the desired index at the correct spot?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
to the index 2 above that one for example, would that not place the desired index at the correct spot?
no.
B4X:
lv.SetSelection(2)
will scroll the 3rd item into the first visible position of the listbox.

xxxxx <--- 3rd item
xxxxx
xxxxx
xxxxx
.......
xxxxx

SetSelection is good if you want for example a "autoscrolling" listview while it fills... See example.
 

Attachments

  • lvitems.zip
    7.5 KB · Views: 254
Last edited:
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
don manfred is right....

I need to know the index of the first visible record on the screen, so I can set accordingly.....
 
Upvote 0
Top