Android Question Simple listview question

Mark.S

Member
Licensed User
Why doesn't this Listview list scroll?


B4X:
Dim DDlist As ListView
        Dim lbl As Label
        DDlist.Initialize("DDlist")
        DropDownPanel.AddView(DDlist, 10dip,40dip,11dip*Wide,28dip*(DDText.Size -1))
        For X =1 To DDText.Size -1
            DDlist.AddSingleLine(DDText.Get(X))
        Next
        DDlist.SingleLineLayout.ItemHeight = 27dip
        lbl = DDlist.singlelinelayout.label
        lbl.TextSize =18
        lbl.TextColor = Colors.Black
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Because you are setting the height to (or close to) the equivalent of the combined height of all the items in the ListView.
B4X:
    DropDownPanel.AddView(DDlist, 10dip,40dip,11dip*Wide,28dip*(DDText.Size -1)) 'The height is being set to the number of items that will be loaded into the ListView * 28dip

Try setting the ListView to a static height that is less than the total height of all the items being loaded into it.

- Colin.
 
Upvote 0

emexes

Expert
Licensed User
Why would it need to scroll when you're making it large enough to show the entire list?

ie: showing (DDText.Size - 1) items, and then setting height of DDList to be large enough to show that many items (with bonus 1dip extra per item?)

edit: Computersmith64 beat me to it (that'll learn me to not go make coffee mid-post) but I'll leave this here because it notes the extra 1dip that presumably is there to make absolutely certain that baby don't scroll ;-)
 
Last edited:
Upvote 0

Mark.S

Member
Licensed User
Thanks for the reply guy's.
The problem was I've have been using this view as a menu selector for 3~8 items.
everythinks was working fine until this list ran out of real estate :confused:.
Simple solution for a silly mistake.
 
Upvote 0

emexes

Expert
Licensed User
The other observation was that you're for-next-ing 1 to n - 1 instead of the more-usual 0 to n - 1 which means you're showing all items except the first one. Dunno about you, but this fixed 0-based indexing is a right pita, alongside signed-bytes-only. Still, I understand that it's much easier to stick with what Java supports, and most everything else about b4a is pretty nifty :)

I didn't explicitly mention the first list item being missed, figured you were using it as a heading or tag or something. No problem with that, but for me and my memory, I now just automatically comment all non-standard loops eg 'skip first item = header which occasionally saves me big-time six months later when I (or someone else) is back in the code.
 
Upvote 0

emexes

Expert
Licensed User
btw the extra 1dip stops the right hand vertical indicator line from appearing when using this view as a menu

So you were indeed actually making sure that baby didn't scroll !?!?

lol. still, we've all had brainfade when battling dragons deep in the code, they must have been some mighty fire-breathers you were fighting.
 
Upvote 0

Mark.S

Member
Licensed User
Thanks emexes,
yeh, the first item is a menu header.

fire-breathers no, got my 2 year old grandson staying with me :eek:
 
Upvote 0
Top