Android Question Multiline ListView..?

JForge

Member
Licensed User
Longtime User
I've been searching the forums for a while now on the best way to handle this, and especially this thread http://www.b4x.com/android/forum/threads/problem-with-listview-itemheight.21163/

All I want to do is just add more than two lines to a listview,
the number of which will be determined by how many results are returned from an SQL query.

I'm looking to use the listview because I like the look and feel of it, its very app like.

Can anyone shed some definitive light on this?

Thanks in advance!
John
 

JForge

Member
Licensed User
Longtime User
Ok, That looks like it should work! Thanks very much! Now it might sound stupid, but how would I go about changing the font size for only the first line so that its bigger and maybe in bold? To be like a header line of sorts..

Again I have to apologize for being so new to all of this but development is going pretty quickly, is exciting!
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
Take a look at the RichString library here.

With it, you would add an item to your customlistview something like this

B4X:
clv1.AddTextItem("Your first line")&CRLF&"{R}{C}Your second line{C}{R}","value")


You will need to add something like the following sub to the CustomListview class

B4X:
'custom addition to this class to add richtext formatting ********************
Sub buildRS(lblTxt As String) As RichString
    Dim rs As RichString
    rs.Initialize(lblTxt)
    rs.RelativeSize2(.8, "{R}")
    rs.Color2( Colors.Cyan, "{C}" )
    rs.RelativeSize2(1.2, "{L}")
    rs.Underscore2("{U}")
    rs.Style2( rs.STYLE_BOLD, "{BI}" )

Return rs

End Sub


Finally, in the CustomListview class, edit the lbl.Text =Text line in the InsertAtTextItem sub to lbl.Text =buildRS(Text)

You can add as many lines to the item as you like using this method
 
Upvote 0

JForge

Member
Licensed User
Longtime User
That is absolutely perfect! Tunderin thank you so much!

Edit4: I didn't add the view before trying to add things too it.....

Edit: I'm getting a Null Pointer Exception here pnl.AddView(lbl, 5dip, 2dip, sv.Width - 5dip, 20dip) and have no clue why, the example code works, but when I try to build the string dynamically it throws that error...

Edit2: The changes you said to make work fine in the example that comes with the customlistview library, just not my actual code.

Edit3: The Error log.

LogCat connected to: emulator-5554
** Activity (main) Create, isFirst = true **


(Main, 68) Object was already initialized. (warning #1003)
customlistview_insertattextitem (B4A line: 112)


pnl.AddView(lbl, 5dip, 2dip, sv.Width - 5dip, 20dip)
java.lang.NullPointerException


at anywheresoftware.b4a.objects.ViewWrapper.getWidth(ViewWrapper.java:125)
at b4a.example.customlistview._insertattextitem(customlistview.java:619)
at b4a.example.customlistview._addtextitem(customlistview.java:69)
at b4a.example.main._getdata(main.java:409)
at b4a.example.main._activity_create(main.java:270)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.main.afterFirstLayout(main.java:89)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
~e: at java.lang.reflect.Method.invoke(Method.java:521)


at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
 
Last edited:
Upvote 0

JForge

Member
Licensed User
Longtime User
I ended up figuring out what I had done wrong, i mentioned it in my post above, would posting my code still be of use to other members?
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Good that you solved it yourself! It's always nice to post part of your code. There will always be people who can learn of it.
Regards
 
Upvote 0
Top