Android Question Listview height

Dman

Active Member
Licensed User
Longtime User
I am having a brain fart at the moment. I have a listview that I add the first line with lvWhatever.addsingleline("Add New") and then I run a for loop to get results from the db.

That all works perfectly but the issue I have is setting the total height of the listview. If it only has the Add New line and 2 lines from the db, I don't want it taking up the whole screen . On the other hand if it has 40 records, I only want it to cover 90%y of the screen.

Is there anything I can do?
 

Dman

Active Member
Licensed User
Longtime User
The example I gave was only an example, not an actual listview so there is a little more to it but here is a screenshot when I use that line.

There are only 3 records so it has a lot of blank space at the bottom. I would rather use a spinner but to get a tablet to show on the play store, the targetsdk needs to be set at 11 and for some reason, my spinners don't show on anything above 10
 

Attachments

  • Screenshot_2013-12-14-17-20-42.png
    Screenshot_2013-12-14-17-20-42.png
    41.5 KB · Views: 179
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You can set the height of each item in your listView, using for e.g.
B4X:
yourListView.singleLineLayout.label.height=chosenHeight
Then calculate the desired listview's height by multiplying label's height by the size of your list. If it's greater than 90% then set it to that, as NJDude previously suggested.
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
That is what I am trying to figure out and where I am having a brain fart.

I can't seem to figure out how to word this line:
(lvheight is a variable that contains dbcursor.rowcount * the label height of 60dip)
lvSearch.Height = lvheight + 120 & "dip"
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
If I understood correctly what you need to do is:
B4X:
lvSearch.Height = lvheight * 60dip

if lvheight = 3 then the height of the list view will be 3 * 60 = 180dip, but you will have to also keep an eye on the height of the device's screen or your ListView will be outside the visible area.
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
That is the first thing that I thought of but never tried it because it didn't look right.

Color me stupid. :)
 
Upvote 0
Top