CustomListView - A flexible list based on ScrollView

Status
Not open for further replies.

ANSA

Member
Licensed User
Longtime User
I am trying to do the first option (going over all Items ad disable them)
I wrote the following SUB, but it dose not seem to work:

'Disable all items.
Public Sub DisableAll
For i = 0 To sv.Panel.NumberOfViews - 1
sv.Panel.Enabled = False
Next
End Sub

any suggestions?
Thank you
 

ANSA

Member
Licensed User
Longtime User
Hi Luca,
it did not work :-(

the funny thing is that, if I use for example (pnl.Visible = False) the code is working fine and the items becomes invisible!

but (pnl.Enabled = False) dose not make the items disabled !!!


thank yiu
 

LucaMs

Expert
Licensed User
Longtime User
Ops... panelXX.Enabled = False does not disable the "children views", If I remember well, sorry.

You should get all views of that panel (pnl in the example):
B4X:
For Each v As View In pnl.GetAllViewsRecursive
    v.Enabled = False
Next


then the code should be:
B4X:
For i = 0 To YourCustomListView.GetSize - 1
    Dim pnl As Panel = YourCustomListView.GetPanel(i)
    pnl.Enabled = False
    For Each v As View In pnl.GetAllViewsRecursive
        v.Enabled = False
    Next
Next
 

ANSA

Member
Licensed User
Longtime User
Thanks luca for the quick reply, I am afraid it did not do anything different than the previous code!!!
any other suggestions?
 

peacemaker

Expert
Licensed User
Longtime User
If to make the LIstview transparent, to get a custom background picture - the checkboxes looks invisible by default (very light-grey) over a light background picture.
If to try to re-draw then by https://www.b4x.com/android/forum/threads/add-border-to-views-and-change-checkbox-graphic.36436/ - old phones and modern Sony - have LIstview of several hundred items - crached due to OutOfMemory (default checkbox has no OOM issue).

ColorDrawable can be applied, but it's only for border over whole the checkbox, not to the square.
SO, question - is there possibility to change only square color of the checkbox ?
 
Last edited:

kozbot

Member
Licensed User
Longtime User
Is it possible to make particular words, all different words in my list bold? I was trying to use Rich String class with it, but it doesn't seem to be working. Ideas? Thanks.
 

peacemaker

Expert
Licensed User
Longtime User
When to use an EditText view on the customlistview and use focus to get the text:
B4X:
Sub lbl_FocusChanged (HasFocus As Boolean)
Dim index As Int = cv.GetItemFromView(Sender)
...

there is the error in the sub
B4X:
Public Sub GetItemFromView(v As View) As Int

B4X:
Error occurred on line: 212 (CustomListView)
java.lang.NullPointerException
    at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:205)
    at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod(Reflection.java:802)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:668)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:334)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:244)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
    at anywheresoftware.b4a.BA$2.run(BA.java:299)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5021)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)

in the line
B4X:
parent = r.RunMethod("getParent")
due to parent got Null after some loops.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Can you upload a small project that demonstrates this issue?
Seems, no, Erel - it is complex project with several activities. And seems, this error occurs when
1) txt_FocusChanged occured, but
2) the listview is cleared at the almost same time.

So it's reproduced not always.
Maybe just a suggestion - how to be in such situation.
Now i use Try\Catch in _FocusChanged.
 

peacemaker

Expert
Licensed User
Longtime User
You should create a little sample project.
Anyway, how do you add the CustomListView? And the EditText? Probably you can post these lines.

As in the sample:

B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Transparent
    Dim chk As CheckBox
    chk.Initialize("chk")
    Dim lbl As EditText
    lbl.Initialize("lbl")
    lbl.InputType = lbl.INPUT_TYPE_NONE
    lbl.Text = Text
    lbl.TextSize = 16
    lbl.TextColor = Colors.Black
    lbl.SingleLine = False

    p.AddView(chk, 0, (Height-30dip)/2, 30dip, 30dip) 'view #0
    p.AddView(lbl, chk.Width, 2dip, Width - chk.Width, Height) 'view #1
    Return p
End Sub

And build:
B4X:
cv.Clear
For i = 0 To l.Size - 1
    Dim p As Panel = CreateListItem(L.Get(i), cv.AsView.Width, 60dip)
    Dim lbl As EditText = p.GetView(1)
    Dim texth As Int = su.MeasureMultilineTextHeight(lbl, l.Get(i)) + 75
    texth = Max(40dip, texth)
    lbl.Height = texth
    cv.Add(p, texth + 10dip, l.Get(i))
    If (i mod 100) = 0 Then DoEvents
Next

And use:

B4X:
Sub lbl_FocusChanged (HasFocus As Boolean)
Try
    Dim index As Int = cv.GetItemFromView(Sender)
    Dim pnl As Panel = cv.GetPanel(index)
    Dim chk As CheckBox = pnl.GetView(0)
    Dim lbl As EditText = pnl.GetView(1)
    If HasFocus Then
        If chk.Checked Then
            chk.Checked = False
        Else
            chk.Checked = True
        End If
        atxtSearch.RequestFocus
    End If
Catch
End Try
End Sub

And somtimes this error occurs during
Dim lbl As EditText = pnl.GetView(1)

So, now only Try helps :-(
 
Status
Not open for further replies.
Top