Android Question [SOLVED] B4xLoadingIndicator & CustomlistView

Chris Guanzon

Active Member
Licensed User
How can I use B4xLoadingIndicator.show when I clicked the item (it's panel) in customlistview?

I want to show the loading indicator then hide it again after 0.5 sec.
 

Chris Guanzon

Active Member
Licensed User
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
Indicator.Show
Sleep(500)
Indicator.Hide
End Sub

I already tried this but the indicator only shows at the last item of customlistview. I want to show it in each item of customlistview I clicked.
 
Upvote 0

Mahares

Expert
Licensed User
Indicator is in the cell items designer.
My indicator is in the clv layout, outside the clv itself, not in the items layout and I changed its color to other than white. If it still does not work, perhaps Erel can help you or a small project demonstrating it may also help
 
Upvote 0

stevel05

Expert
Licensed User
It sounds like you are not loading the items into the clv correctly, post the code or upload a small project that shows how you are loading the items.
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
It sounds like you are not loading the items into the clv correctly, post the code or upload a small project that shows how you are loading the items.

My indicator is in the clv layout, outside the clv itself, not in the items layout and I changed its color to other than white. If it still does not work, perhaps Erel can help you or a small project demonstrating it may also help

Please see attached file, I uploaded a small project.
 

Attachments

  • 1.zip
    10.8 KB · Views: 92
Upvote 0

stevel05

Expert
Licensed User
A couple of things you need to know.

1. When you have a global variable for an view on a layout that is loaded multiple times, it will only point to the view on the last layout loaded, which is why the last item is activated every time.
2. The convention for Custom views is to store the actual object in the Tag property of the base panel. Most B4x libs should follow this convention.

So changing the ItemClick sub to:

B4X:
Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Dim P As B4XView = CustomListView1.GetPanel(Index) 'The base panel for the view - that the layout is loaded into.
    Dim LI As B4XLoadingIndicator = P.GetView(0).Tag        'GetView(0) The B4xLoadingIndicator as it's the first view in the layout views tree
    LI.Show
    Sleep(1500)
    LI.Hide
End Sub

is enough to make it work.
 
Last edited:
Upvote 0

Chris Guanzon

Active Member
Licensed User
Thanks @stevel05

I have a question, in the image below, to get the index of view is

pItem = 0
pStatusItem = 1
lblAdvisoryDate = 2
lblAdvisoryTitle = 3
indicatorListItem = 4

Is this correct?

1604103338740.png
 
Upvote 0

stevel05

Expert
Licensed User
Not quite, presumably pItem is a panel, so

GetView(0) will get the pItem,
GetView(0).GetView(0) will get the pStatusItem
GetView(0).GetView(1) will get the lblAdvisoryDate
GetView(0).GetView(2) will get the lblAdvisoryTitle
GetView(1) will get the indicatorListItem
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
Not quite, presumably pItem is a panel, so

GetView(0) will get the pItem,
GetView(0).GetView(0) will get the pStatusItem
GetView(0).GetView(1) will get the lblAdvisoryDate
GetView(0).GetView(2) will get the lblAdvisoryTitle
GetView(1) will get the indicatorListItem

thanks a lot! Now I get it, how it works.
 
Upvote 0

Chris Guanzon

Active Member
Licensed User


I tried it in my project, I'm getting this error.


B4X:
Error occurred on line: 174 (Dashboard)
java.lang.ClassCastException: java.lang.String cannot be cast to b4a.example.b4xloadingindicator
    at b4a.example.dashboard$ResumableSub_CustomListView1_ItemClick.resume(dashboard.java:774)
    at b4a.example.dashboard._customlistview1_itemclick(dashboard.java:740)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1082)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1045)
    at b4a.example3.customlistview$ResumableSub_PanelClickHandler.resume(customlistview.java:805)
    at b4a.example3.customlistview._panelclickhandler(customlistview.java:748)
    at b4a.example3.customlistview._panel_click(customlistview.java:735)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5675)
    at android.view.View$PerformClick.run(View.java:22641)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
 
Upvote 0

stevel05

Expert
Licensed User
Is the layout in your project different to the example? Have you changed the indexes to match?
 
Upvote 0

wes58

Active Member
Licensed User
thanks a lot! Now I get it, how it works.
I don't know if you find it useful or not, but I never do it this way.
What I do is assign a tag to each view (label, button, imageview etc.) and check all views looking for the one I want
For example:
B4X:
    Dim p As B4XView = clv1.GetPanel(clvIndex)
    For Each v As B4XView In p.GetAllViewsRecursive
        If v Is Label then
            if  v.Tag = "2" Then
                do something
            Else If v.Tag = "3" then
                do something
            Endi If
        Else If v Is Button then
             If v.Tag = "3" Then
                do something
            End If
        Else If v is Panel then
            If v.Tag = "25" then
                do something
            End If
        End If
    Next
Of course you can assign a meaningful name to a tag (it may relate to the view function) or just use numbers. If you use numbers in designer, you have to remember the the number is treated as a string i.e. if v.Tag = "2" Then will work, but if v.Tag = 2 Then will not.
I find it easier than trying to remember which view has what index.
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
I don't know if you find it useful or not, but I never do it this way.
What I do is assign a tag to each view (label, button, imageview etc.) and check all views looking for the one I want
For example:
B4X:
    Dim p As B4XView = clv1.GetPanel(clvIndex)
    For Each v As B4XView In p.GetAllViewsRecursive
        If v Is Label then
            if  v.Tag = "2" Then
                do something
            Else If v.Tag = "3" then
                do something
            Endi If
        Else If v Is Button then
             If v.Tag = "3" Then
                do something
            End If
        Else If v is Panel then
            If v.Tag = "25" then
                do something
            End If
        End If
    Next
Of course you can assign a meaningful name to a tag (it may relate to the view function) or just use numbers. If you use numbers in designer, you have to remember the the number is treated as a string i.e. if v.Tag = "2" Then will work, but if v.Tag = 2 Then will not.
I find it easier than trying to remember which view has what index.

Thanks! This is very useful, will use it in my future app. For now, I will stick to @stevel05 code. :)👍
 
Upvote 0

Mahares

Expert
Licensed User
find it easier than trying to remember which view has what index.
Your method is viable too because you do not have to worry about keeping track of the designer tree views indices. Perhaps in this thread 's case, it can be abbreviated like this:
B4X:
Dim p As B4XView = CustomListView1.GetPanel(Index)
    For Each v As B4XView In p.GetAllViewsRecursive
         If v.Tag Is B4XLoadingIndicator Then
            Dim x As B4XLoadingIndicator=v.tag
            x.Show
            Sleep(1500)
            x.Hide
        End If
    Next
 
Upvote 0
Top