Android Question CustomListView; Bottom up.

MikeGOTO

Member
Is there a relatively easy way to populate and scroll a ListView (or any other view) from the bottom up? I am reading UDP Packets of GPS data and want to display the most recent 10 entries; self-scrolling. It would look very similar to the log display while compiling/running from the B4A IDE. I have been searching the forum and experimenting for several days with no luck. I did see a third party presented "UltimateListView", but I would like to stick with standard code.

I also need to remove all but the last 50 or so entries. The UDP stream produces a huge amount of data, and never stops. I envision memory problems if overloading. I have been attempting CustomListView1.RemoveAt(i), with a rolling counter, but no real success.

Forgive me if this is a trivial question - I will likely be asking a few. Other then a little VBA, this is my first foray into OOP. FORTRAN, well there is a language I can speak. Visual FORTRAN - now that's an idea...
 

MikeGOTO

Member
The intent is to load latest data (all text) to the bottom of the view, automatically scrolling everything up one element. There is a Pause/Resume button that closes the UDPSocket. When paused the user should be able to drag down, scrolling to previous entries (up to a memory imposed limit). Again, it should look and work very similar to the log view on the B4A IDE.

If there is a better view to accomplish this, I am totally open.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If it is just text then it might be simpler to use EditText or BBCodeView, though xCLV is also good.

Is there a relatively easy way to populate and scroll a ListView (or any other view) from the bottom up?
Create a tall empty item and add it as the first item. Later add items with CLV.Add and scroll to the bottom.
 
Upvote 0

MikeGOTO

Member
Regarding use of CLV, did you mean CLV.AddText rather than CLV.Add? I am only loading text, so I do not understand "Create a tall empty item and add it as the first item".

I have seen EditView suggested as a view for lists, but I cannot seem to make it display more than a single item. How might this look?

many thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Regarding use of CLV, did you mean CLV.AddText rather than CLV.Add?
Both options are good.

I am only loading text, so I do not understand "Create a tall empty item and add it as the first item".
B4X:
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 600dip, CLV.AsView.Width)
CLV.Add(p, "")
 
Upvote 0

MikeGOTO

Member
Definitely confused. I am not certain if I am fumbling my question, or if putting a simple, scrolling, text-only, read-only, list of messages is as complicated as it seems. I have not yet got as far as understanding the XUI library or what B4XView is all about. Is there a simple way to do this with the views available in the Designer? I keep seeing EditView mentioned as an easy option, but I cannot get it to load more than a single item. EditView does not seem to have index or scrolling control. I want to list 10 messages, newest to the bottom, oldest scrolling off the top; just like the log display in the IDE.
 
Upvote 0

MikeGOTO

Member
I will dive into XUI and B4XView.

In the meantime,

Yes on:
EditText1.SingleLine=False

On every event - UDP_PacketArrived
I populate the EditText:

msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
msg=msg.SubString2(0,18)
EditText1.=msg

The message is displayed at the bottom of the EditView, but each subsequent message overlays the previous. Only one message displayed at a time. I seems to be missing something - probably simple, but important.
 
Upvote 0

MikeGOTO

Member
That does it. So a multi-line EditView is a single text string with embedded CRLFs.

Thank you very much. I will research the XUI and B4XPages if I need to pretty it up.
 
Upvote 0
Top