Android Question Doevents problem

grafsoft

Well-Known Member
Licensed User
Longtime User
I fill a scrollview, it takes a frrw seconds. So I want a progressbar or something like that. Therefore, during the filling of the scrollview, I need a DoEvents statement. But then it is impossible to scroll!

Any ideas?

B4X:
For iz=0 To cr.Rowcount-1
     cr.position=iz
     aid=cr.GetString ("AID")
     na=cr.GetString ("name")
     nu=cr.Getstring ("number")
    
    
    
     ' Log (na)
     isasked = cr.getint ("isasked")
     iscontact=cr.GetInt ("iscontact")
    
     Dim pnlpers As Panel
    pnlpers.Initialize("pnlpers")
     pnlpers.Color=Main.ptealcolor
     Scroll.Panel.AddView(pnlpers,0dip,iz*hei,Scroll.Width,hei)
     pnlpers.Tag=s
     Dim shoplbl As Label
     shoplbl.Initialize ("shoplbl")
    
     If Basis.ispad=True Then
       Basis.dolabel (shoplbl,na & " / "  & nu)
     Else
       Basis.dolabel (shoplbl,na & CRLF & nu)
     End If
     shoplbl.Gravity = Gravity.CENTER
     If iscontact=1 Then
       shoplbl.color=Main.a200color
       shoplbl.TextColor=Colors.White
     Else If isasked=1 Then
       shoplbl.color=Main.a100color
       shoplbl.TextColor=Colors.White
     End If
    
     pnlpers.AddView(shoplbl,3dip, 3dip, Scroll.Width-6dip, hei-6dip)
    
     Dim Contacts2 As Contacts2
     Dim listOfContacts As List
     listOfContacts = Contacts2.FindByName(na, True, False, False)
     Dim l As Label
     l.Initialize ("l")
     If listOfContacts.Size > 0 Then
       Dim Contact As Contact
       Contact = listOfContacts.Get(0)
       Log(Contact) 'will print the fields to the LogCat
       Dim photo As Bitmap
       photo = Contact.GetPhoto
      
       If photo <> Null Then
        

         pnlpers.AddView(l,3dip, 3dip, hei-6dip, hei-6dip)
        
         l.SetBackgroundImage(photo)
       End If
     End If
     Dim m As Map
     m.Initialize
     m.Put ("aid",aid)
     m.Put ("name",na)
     m.Put ("number",nu)
     m.Put ("isasked",isasked)

     s=Basis.MapToJSON (m,True)
     shoplbl.Tag=s
    
     ' when I leave this uncommented, the scrollview is unscrollable
     ' DoEvents
    
   Next
   Scroll.Panel.Height=(cr.rowcount)*hei
  
   ' Msgbox (Scroll.Panel.Height,cr.rowcount)
  
   Scroll.height=100%y
   Scroll.color=Main.lbcolor
 

grafsoft

Well-Known Member
Licensed User
Longtime User
What ddo you mean by "reuse the list of contacts"?

I need to have the list of contacts in my table because I need additional information about them.

Thanks for the hint with the picture.
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
I'm not sure what you want to do, but that's an awful lot of code inside a For/Next cycle.

Given the last time you use the "iz" variable, your cycle should end as shown below:
B4X:
For iz=0 To cr.Rowcount-1
     cr.position=iz
     aid=cr.GetString ("AID")
     na=cr.GetString ("name")
     nu=cr.Getstring ("number")
   
   
   
     ' Log (na)
     isasked = cr.getint ("isasked")
     iscontact=cr.GetInt ("iscontact")
   
     Dim pnlpers As Panel
    pnlpers.Initialize("pnlpers")
     pnlpers.Color=Main.ptealcolor
     Scroll.Panel.AddView(pnlpers,0dip,iz*hei,Scroll.Width,hei)
     pnlpers.Tag=s
     Dim shoplbl As Label
     shoplbl.Initialize ("shoplbl")
Next

The remaining code should be outside.
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
Cannot be ... I need to fill the label with data which I later need with a shoplbl_click method.
 
Upvote 0

grafsoft

Well-Known Member
Licensed User
Longtime User
I put out the part with the photos, it is not necessary. Now it runs fast enough. Thank you!

But still the question remains: With DoEvents the scrollpanel cannot scroll anymore, without it can.
 
Upvote 0
Top