CustomListView - A flexible list based on ScrollView

Status
Not open for further replies.

Noize

Member
Licensed User
Longtime User
I Can't see the CustomListView on Designer, I've added the CustomListVIew class in IDE but If I create a CustomView I can't find the CustomLIstView type, any idea?.

Tnx
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should be listed in the Custom Type field:
SS-2014-11-17_08.51.18.png
 

migrec

Member
Licensed User
Longtime User
Hey I can't get this working, it compiles fine but gives me a java.lang.nullpointerexception error
B4X:
ListView1.Add(CreateListItem(titles(0),ListView1.AsView.Width,50dip),50dip,titles(2))
Listview1 is a customlistview
titles() are strings
I can't see why this shouldn't work, could someone point me at right direction?
 

migrec

Member
Licensed User
Longtime User
okay, here it is:
B4X:
LogCat connected to: B4A-Bridge: Sony Ericsson ST17i-358510041014453
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Service (widget2x1) Start **
** Service (widget2x1) Start **
** Service (widget2x1) Start **
** Service (widget2x1) Start **
** Service (widget2x1) Start **
** Activity (home) Resume **
** Activity (home) Pause, UserClosed = false **
running waiting messages (21)
** Activity (main) Resume **
** Service (service1) Destroy **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
** Service (service1) Destroy **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (home) Create, isFirst = true **
** Activity (home) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Activity (home) Pause, UserClosed = false **
** Activity (games) Create, isFirst = true **
java.lang.NullPointerException
    at anywheresoftware.b4a.objects.ViewWrapper.getWidth(ViewWrapper.java:128)
    at b4a.example.games._listviewmanager(games.java:491)
    at b4a.example.games._activity_create(games.java:318)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at b4a.example.games.afterFirstLayout(games.java:98)
    at b4a.example.games.access$100(games.java:16)
    at b4a.example.games$WaitForLayout.run(games.java:76)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4441)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
** Service (widget2x1) Start **
 

migrec

Member
Licensed User
Longtime User
Erel seem to be busy, does anyone else have a clue, I've still not solved it :(
 

migrec

Member
Licensed User
Longtime User
this is the error line:
B4X:
ListView1.Add(CreateListItem(titles(0),ListView1.AsView.Width,50dip),50dip,titles(2))
¨
and this is the code in ListViewManager:
B4X:
Sub ListViewManager
    ListView1.Initialize(Me, "ListView1")
    splitstrings = Regex.split(Chr(13)&Chr(10), File.GetText(File.DirRootExternal, "data.txt"))
    For i = 0 To splitstrings.Length - 1
    titles = Regex.split(",", splitstrings(i))
    ListView1.Add(CreateListItem(titles(0),ListView1.AsView.Width,50dip),50dip,titles(2))
    Next
End Sub
 

migrec

Member
Licensed User
Longtime User
sorry but don't really understand this thing with customviews and get this error while compiling: customlistview cannot be converted to View

this is how it looks like now:
B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim Panel1 As Panel
        Panel1.Initialize("")
        Panel1.Color = Colors.Black
        Dim Button1 As Button
        Dim Label1 As Label
        Label1.Initialize("")
        Button1.Initialize("button") 'all buttons click events will be handled with Sub Button_Click
        Panel1.AddView(Label1, 5dip, 2dip, 150dip, Height - 4dip) 'view #0
        Panel1.AddView(Button1, 155dip, 2dip, 110dip, Height - 4dip) 'view #1
        Panel1.AddView(ListView1,0,0,100%x,100%y)
        ListView1.Add(CreateListItem(titles(0),ListView1.AsView.Width,50dip),50dip,titles(2))
        Button1.Text = "Download"
        Label1.Gravity = Bit.OR(Gravity.CENTER_VERTICAL, Gravity.LEFT)
        Label1.Text = Text
        Label1.TextSize = 16
        Label1.TextColor = Colors.Black
        Return Panel1
End Sub
 

Tom1s

Member
Licensed User
Longtime User
Hi
Tried to make customlistview in sliding menu transparent so that background image is visible. Color gives an error and scrollingbackgroundcolor... Where those should be put?

B4X:
sm.Initialize("sm")
   Dim offset As Int = 60%x
   sm.BehindOffset = offset
  sm.Mode = sm.LEFT

clv3.Initialize(Me, "clv3")
sm.Menu.AddView(clv3.AsView, 10dip, 47dip, 100%x - offset - 20dip, 100%y)

For i = 1 To 3
clv3.Add(CreateListItem("Graph" & i, clv3.AsView.Width, 50dip), 50dip, "Graph" & i)
Next
clv3.Add(CreateListItem("hello", clv3.AsView.Width, 50dip), 50dip, "hello")
Dim b2 As Bitmap
b2.Initialize(File.DirAssets,"bg2.png")
sm.Menu.SetBackgroundImage(b2)
clv3.Color = Colors.Transparent 'gives error
clv3.ScrollingBackgroundColor = Colors.Transparent ''gives error

Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
Dim p As Panel
p.Initialize("")

p.Color = Colors.Transparent 'doesn't work
Dim b As Bitmap
b.Initialize(File.DirAssets,"success.png")
Dim i As ImageView
i.Initialize("")
i.Bitmap = b
Dim lbl As Label
lbl.Initialize("lbl")
lbl.Text = Text
lbl.TextSize = 16
lbl.TextColor = Colors.White
p.AddView(i, 0,0,Height,Height)
p.AddView(lbl, Height+5dip,0,Width/3,Height)
Return p
End Sub
 
Last edited:

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
using the second list how can I set enabled = False some buttons, maintaining the same event for each button??
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
I did:

B4X:
Dim pnl As Panel
pnl = listApk.GetPanel(itemKey)
Dim b As Button
b = pnl.GetView(1)
Log("b: " & b.Text)
 

rzv25

Member
Licensed User
Longtime User
I have a silly question about custom listview. I want to have the grid lines (separators) of colour gray. So I set sv.Color =colors.gray in the CustomListVIew class. The problem is that the listview is spread across entire display and if I only have 1 or 2 items in the list, the empty part of the list is displayed gray. And I want it black.
What properties do I need to set in order to have the grid lines one colour and the listview background another color ?

Also, another question. Can I add a header to the list ?

Thank you
 
Last edited:
Status
Not open for further replies.
Top