Android Question ListView.TwoLinesLayout question

Gaver Powers

Member
Licensed User
Longtime User
I am populating a ListView control with the results of a query converted to JSON and added to the ListView using the

B4X:
ListView1.AddTwoLines2(lvd.SecondRow,lvd.FirstRow,lvd.FirstRow)

process.

I'm hiding the SecondLabel in the control using:

B4X:
ListView1.TwoLinesLayout.SecondLabel.Visible = False

This results in every other line of the ListView being blank.

Is there anyway to remove the line from the presentation so the items being shown are continuous without gaps? Like maybe format the height of the supposedly hidden label to zero?

When I click on a selection - the blank row is highlited and not the subject row with the text in it, but it does pass the right value lvd.FirstRow to the click event.

hope so...

GP
 

DonManfred

Expert
Licensed User
Longtime User
you can play with the height of secondlabel AND with the height for the item itself... there are two you have to change i remember...

on the other side... Why you use twolineslayout and remove the second label when you just could use oneline layout.
 
Upvote 0

Gaver Powers

Member
Licensed User
Longtime User
Don, thanks for the (really rapid) response!
I'm passing the unique id and a text string to the control.
In JSON it represents it with an index number eg 0 id=49 name=test1; 1 id=84 name=test2;
SAMPLE:
B4X:
 [{"id":"1","bus_name":"Gaver"},{"id":"79","bus_name":"Daniels Sharpsmart Inc"},{"id":"78","bus_name":"IT-DEPARTMENT (TEST)"},{"id":"68","bus_name":"Waste Management"},{"id":"27","bus_name":"SMD Warehouse"},{"id":"6","bus_name":"SMD TDF"},{"id":"4","bus_name":"City of Tampa \/ Mackay Bay"},{"id":"3","bus_name":"Waste Management"},{"id":"1","bus_name":"B&D BIOMEDICAL WASTE SVCS."}]
When I tried loading that into a SingleLine ListView control - all I could get back from the Click event was the array index number, not the unique ID number that I needed.

Maybe I'm not setting it up correctly?

So I tried the TwoLine method - and I'm now getting the correct id number (not the array index id) - but the format is not pretty :(

I'm unable to find a method or property for setting SecondLabel.height - can you point me in the right direction for those properties?

Thanks again,

GP
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Stop.
You have this jsonstring, right?
[{"id":"1","bus_name":"Gaver"},{"id":"79","bus_name":"Daniels Sharpsmart Inc"},{"id":"78","bus_name":"IT-DEPARTMENT (TEST)"},{"id":"68","bus_name":"Waste Management"},{"id":"27","bus_name":"SMD Warehouse"},{"id":"6","bus_name":"SMD TDF"},{"id":"4","bus_name":"City of Tampa \/ Mackay Bay"},{"id":"3","bus_name":"Waste Management"},{"id":"1","bus_name":"B&D BIOMEDICAL WASTE SVCS."}]

Now you want to fill a listview with the contents of this json, right?

In this case for example

id=1
bis_name=Gaver

Gaver should be the content of listview-item and if you click on that item you want to know the id 1. Right???
Daniels Sharpsmart Inc would give an id 79 then...

Did i understand that right? Where did you get the json from? Is it an result from an httputils-call?

Can you post your project? it is easier to answer if you know the code you are using...
 
Upvote 0

Gaver Powers

Member
Licensed User
Longtime User
Yes, obtained from an httputils call to MySQL Db.
But when I loaded into the listview control - it assigned the id of the array element (0;1;2;3;4 .. n)
Based on your message above - I'm re-examining the SingleLine method again to see if I missed a process...

Looking at AddSingleLine2 now.

G
 
Upvote 0

Gaver Powers

Member
Licensed User
Longtime User
Thanks Don,

You got me on the right track.
Got the AddSingleLine2 process working, now working on the styling.

TYVM!
G
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Short princtiple you can use in your code (attapt the code to your needs)

Do this (incl DIM) for each item...
B4X:
    Dim retmap As Map
    retmap.Initialize
    retmap.Put("id",1) ' put id from json here instead the 1
    retmap.Put("bus_name","Test") ' put busname from json here instead of "Test"
    retmap.Put("bla","blub") ' put any more informations about the item here in this map and access them later in clicksub
    lv.AddSingleLine2(retmap.Get("bus_name"),retmap)

BTW: This also works with
B4X:
lv.AddTwoLines2
and
B4X:
lv.AddTwoLinesAndBitmap2

then you can use this clicksub and get any information about the item you stored in retmap while filling the list

B4X:
Sub lv_ItemClick (Position As Int, Value As Object)
    Dim retmap As Map = value
    Log(retmap.Get("bus_name")&" has id "&retmap.Get("id"))
End Sub
 
Last edited:
Upvote 0
Top