B4A Library [lib]mListView based on native ListView

mListView based on native ListView
differents between ListView(in b4a)
implement :
1.divider(drawable,get or set height)
2.selected drawable (differents between Usually state)
3.scroll event(use to do something like:load next page,load last page,judge with this event)
4.FooterView and HeaderView
how to code:
'must like ListView
dim lv as mListView
   Dim itbg,itbgp As BitmapDrawable
   Dim cd As ColorDrawable
        Dim lbh,lbf As Label
   lv.SetData'call this after footer and header,must before you add any 
'data in listview
        For i=1 To 200

Author: IceFairy333
Version: 1.2

  • Fields:
    • Background As Drawable
    • Label As LabelWrapper
    • SecondLabel As LabelWrapper
    • SelectedBackground As Drawable
    • ItemHeight As Int

  • Fields:
    • Background As Drawable
    • ImageView As ImageViewWrapper
    • Label As LabelWrapper
    • SecondLabel As LabelWrapper
    • SelectedBackground As Drawable
    • ItemHeight As Int

  • Fields:
    • Background As Drawable
    • Label As LabelWrapper
    • SelectedBackground As Drawable
    • ItemHeight As Int
  • mListView
    • itemclick (Position As Int, Value As Object)
    • itemlongclick (Position As Int, Value As Object)
    • onscroll (view as Object As , firstVisibleItem as int As , visibleItemCount as int As , totalItemCount as int As )
    • onscrollstatechanged (view as Object As , scrollState as int As )
    • Status_scroll_begin As Int
    • Status_scroll_end As Int
    • nCurSel As Int
    • AddFooterView (vf As View)
      call this before SetData
    • AddHeaderView (vh As View)
      call this before SetData
    • AddSingleLine (Text As String)
    • AddSingleLine2 (Text As String, ReturnValue As Object)
    • AddTwoLines (Text1 As String, Text2 As String)
    • AddTwoLines2 (Text1 As String, Text2 As String, ReturnValue As Object)
    • AddTwoLinesAndBitmap (Text1 As String, Text2 As String, Bitmap As Bitmap)
    • AddTwoLinesAndBitmap2 (Text1 As String, Text2 As String, Bitmap As Bitmap, ReturnValue As Object)
    • BringToFront
    • Clear
    • GetItem (Index As Int) As Object
    • GetSelection As Int
    • Initialize (arg1 As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveAt (Index As Int)
      if index=nCurSel then nCurSel=-1
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetData
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetSelection (Position As Int)
    • Background As Drawable
    • Color As Int [write only]
    • Divider As Drawable
    • DividerHeight As Int
    • Enabled As Boolean
    • FastScrollEnabled As Boolean
    • Height As Int
    • Left As Int
    • ScrollingBackgroundColor As Int [write only]
    • SingleLineLayout As SingleLineLayout [read only]
    • Size As Int [read only]
    • Tag As Object
    • Top As Int
    • TwoLinesAndBitmap As TwoLinesAndBitmapLayout [read only]
    • TwoLinesLayout As TwoLinesLayout [read only]
    • Visible As Boolean
    • Width As Int


  • lv.jpg
    63.7 KB · Views: 4,145
  • mListView.zip
    12.9 KB · Views: 2,208
Last edited:


Licensed User
Longtime User
SelectedBackground is awesome.

Can you add a functions like
ScrollToItem(Position/ItemID) to scroll without selecting, or
SetSelectionCenter2 that selects and scrolls that the item is about the middle of the visible list if possible.

Also would be of great help for advanced features to have something like GetScrollPosition. Plus a possibility to change SelectedBackground during runtime would be great (invalidate does not work; SetData does but has some visual sideeffects and probably not recommend anyway)


Licensed User
Longtime User
Had this issue when using this library.
I wonder if you use multiple mListViews. if so, does this happen on all ListView views?
Btw, are using regular ListViews too?


Licensed User
Longtime User
Is it possible to integrate RichStrings for more color and formats in mListView?
Then mListView would be perfekt!

Thank You


Active Member
Licensed User
Longtime User
I have some problem with this ListView.

When I use something like this:

dim p as Panel



Sub lv1_ItemClick (Position AsInt, Value As Object)
End Sub

I expect that the value is the same as p (of type Panel) but when I look into the debugger it is anywheresoftware.b4a.BALayout@419e5e90

The program crashes in ItemClick because value is not of type p.

Peter Simpson

Licensed User
Longtime User
Hello @icefairy333, thanks for posting this library.

If you add a header using this library, tapping on that header causes the following error.
java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1.

@icefairy333 tap on the header in your own example that you included in your first post, your example also crashes when tapping on the header .

Tapping on the footer does not cause any issues, only tapping on the header causes an issue in the _itemclick event.

Thank you...
Last edited:


Licensed User
Longtime User
your example also crashes when tapping on the header
i saw that lib. and i tried with no success.

One more reason for the requirement i created in the last months... my wish to extend b4a

I just told lemonisdead something about that subject

i just past it here. You are maybe interested in this too
----------- snip -----------------------------
So i came into first contact to java and Android programming. Tried to get rid of developing andoid app with eclipse in java,,, THREE WEEKS with NO success....
Then i found B4A and tried the demo and within three days i had a first release for that app. I FELL IN LOVE INTO B4A :)
To finish the released app (in google in beta-stadium to be not public) i needed 4 weeks. Two apps and a addition in our software (see above). After that i dont need to write apps for our company. Just this... All i did here in the forum the last two years i did cause i was in love in b4a. In the REALLY HELPFUL community... B4A is my Hobby now you can say.
I learned a lot, i tried all Example in the forum. ok, maybe not ALL ;-) But lot of them. I learned from the examples and wrote one or two (maybe more (3092 :D)) posts here in forum to help and give something back for the suppport i earned. Or the support i SAW that someone got here in forum (Erel,NJDUDE,TDS,Wrwound, Informatix and so one.... They all gave great support. I i love that.... And i got a lot of likes too. I like that too :D
So i was on the hunting on everone on the "Noteable Members" list.... I´m 3rd in likes i think :))))))))))
I also found some new friends here (you included)
So. I gave something back to community. Then, when times goes by and i fall deeper and deeper in love with b4a and due to this i feel the requirement (for me and for the community which can use such a really great Developmentenronment).... i feel the requirement to Extend B4A... All i could do was to give good advices in forum...
It gave a good feeling. But later that was "not enough"... "I WANT EXTEND B4A!"
End of September 2014 i wrote a mail to erel asking him whether he can give me the source of Dropbox-Sync-Library. I wanted to give additions to this Library.
I got the Source from Erel and started learning java to extend this library.
You know what is today :)
UFF... That was much to type. I hope it is not boring to read all that shit :D
Last edited:


Well-Known Member
Licensed User
Longtime User
This is a nice library. The SelectedBackground feature itself is worth switching to this.

But currently, when I longpress an item, the background color is Holo Blue. Is it possible to change it?

Revisiting this request after 1.5 years. With Android 5 Material Design, things have gone even bad. On Android 5 devices, the hover color is grey while on 4.x devices it is Holo Blue. So much inconsistency.

It would be great if we can somehow set the drawable for longpress (or at least set it to Null so that it doesn't show up). There is a method discussed here to achieve this via XML, by overriding ItemBackgroundHover.


Wish we could do this on B4A.


Licensed User
Longtime User
How to set scroll possiton. i use "liste.Status_scroll_begin" command like liste.Status_scroll_end=100 but. it does nothing.


Licensed User
Longtime User
Hello icefairy333,
is it possible to make a Update for the great mListview with functions of the new native ListView?

Thank You