Android Question customlistview and progressdialog

leitor79

Active Member
Licensed User
Longtime User
Hello,

I'm loading a customlistview with several items in a For-Loop; since the loading takes an "uncomfortable" amount of time -seconds-, I was looking for a way to show an -animated- progress dialog.

Using doevents problem is (sort of) solved, but I've read advice against using doevents.

I've paginated the load to 25 items at a time, but it stills takes 2 seconds to load (in my note 3), so I'd still want to put some (animated) progress dialog to make a friendliest possible UI for users with slower devices.

I have a list of items to load into the customlistview, like this:


B4X:
        Dim P as panel
        For Each M As myObject In MyList.Values 
            P.Initialize("")
            P.Loadlayout("MyLayout")
            .
            .
            .
            (doing stuff with the panel)
            .
            .
            .
            MyCustomListView.Add(P, 2dip, M)
        Next


Any other tip for speeding up the load would be appreciated. For example; I've tried to disable the animation (from code) when the panel is added but I can't find where to change that.

Thank you very much!
 

leitor79

Active Member
Licensed User
Longtime User
Hi Erel, thank you for your answer!

1 - No, debug mode... I know release mode is faster, but I don't know if it'd be fast enough on most devices

2 - Yes, but after loading the item's list, I also add items one by one, and at that moment the animation is nice

3 - No.

Thank you very much!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Dim P as panel
For Each M As myObject In MyList.Values
P.Initialize(
"")
P.Loadlayout(
"MyLayout")
You are initialize the panel for each object in MyList new and load the layout new each time. Assuming your list has 100 items them you initialize the panel 100 times and you load the panels layout 100 times.

Looks weird/wrong to me

B4X:
Dim P as panel
P.Initialize("")
P.Loadlayout("MyLayout")       
For Each M As myObject In MyList.Values
  ' do domething with the panel....
 
Upvote 0

leitor79

Active Member
Licensed User
Longtime User
Hi DonManfred, thank you for your answer!

What I thought (I'm coming from VB6 and Visual Studio) is an equivalent of the "New" clause. So, I initialize the panel each loop because I add a new panel every loop. Is that wrong?

MyLayout has 2 labels, Label1 and Label2, I do stuff with them. I have those views declared in the Sub Globals:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   
    Private Label1 As Label
    Private Label2 As Label

And I use them on every loop, something like this:


B4X:
Dim P As Panel
Dim su As StringUtils
Dim h1 as Integer

For Each M As myObject In MyList.Values
   
    P.Initialize("")
    P.Loadlayout("MyLayout")
   
    If M.Property1 = True then
        Label1.Left=10dip
    Else
        Label1.Left=100%x - Label1.Width - 10dip
    End If
   
    Label1.Text = M.Property2
    h1 = su.MeasureMultilineTextHeight(Label1,M.Property2)
    Label1.Height = h1

    Label2.Text = M.Property3    

    MyCustomListView.Add(P, h1 + 2dip, M)

Next


....Or when Label1 and Label2 are initialized with the current panel?

Thank you very much!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Is that wrong?
if you want to create a NEW panel on each iteration then you need to do the DIM inside the loop; not outside

In this case;
change
B4X:
Dim P as panel
P.Initialize("")
P.Loadlayout("MyLayout")      
For Each M As myObject In MyList.Values
  ' do domething with the panel....

to
B4X:
For Each M As myObject In MyList.Values
  Dim P as panel
  P.Initialize("")
  P.Loadlayout("MyLayout")      
  ' do domething with the panel....
 
Upvote 0

leitor79

Active Member
Licensed User
Longtime User
Thanks for your answer again, Don.

The code I've pasted is a sketch of the real function. The For-Loop calls a function that declares the panel and initializes it, among 140 lines of code of many other stuff (heights, widths, colors), so at the end the panel is inside the loop. Sorry for misleading you.

Another doubt I have: would it be more efficient (fast?) to set widths and heights in the layout's script, or in code, as in the example?

Thank you very much!
 
Upvote 0
Top