Android Question MapFragment with CustomListView

Discussion in 'Android Questions' started by Multiverse app, Dec 18, 2018.

  1. Multiverse app

    Multiverse app Active Member Licensed User

    The Goal is to Add MapFragment with Customlistview while using LazyLoading. After the mapfragment is ready, add a marker to all of the maps.

    Screenshot_1545106453.png

    The Problem is that at VisibleRangeChanged, mfclvorders_Ready is called for only the last MapFragment. Therefore, All the maps except the last are left blank.

    The Following code populates the customlistview by looping through a map 'mapor':
    Code:
    For j = 0 To mapor.Size - 1
                                    
    Dim CLI As CreateListItemClvOrders:CLI.Initialize
                                    
    Dim IncomingMapnext As Map=mapor.GetValueAt(j)

                                        CLI.maporders=IncomingMapnext
                                        
    Dim xui As XUI
                                        
    Dim p As B4XView = xui.CreatePanel("")
                                        p.SetLayoutAnimated(
    30000, clvorders.AsView.Width, 50%y)
                                        clvorders.Add(p, CLI)

                                
    Next
    Code for VisibleRangeChanged:
    Code:
    Dim ExtraSize As Int = 1
        
    For i = 0 To clvorders.GetSize-1
            
    Dim p As B4XView = clvorders.GetPanel(i)
            
    If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
                
    If p.NumberOfViews = 0 Then
                    
    Dim CLI As CreateListItemClvOrders = clvorders.GetValue(i)
                    p.LoadLayout(
    "clvorders")


                    
    Wait For mfclvorders_Ready
                    
    Log("clvorders_VisibleRangeChanged"&i)
                    
    Dim maptemp As Map=CLI.maporders
                    mfclvorders.GetMap.AddMarker(maptemp.Get(
    "latitude"), bllon=maptemp.Get("longitude"), "Pickup Point").Snippet="Pickup Point"
                    
    Dim cp As CameraPosition:cp.Initialize(maptemp.Get("latitude"), bllon=maptemp.Get("longitude"), 10)
                    mfclvorders.GetMap.AnimateCamera(cp)

                
    End If
            
    Else
               
    'not visible
               If p.NumberOfViews > 0 Then
                   p.RemoveAllViews 
    '<--- remove the layout
               End If
            
    End If
        
    Next
    MapFragment is not a view(does not return a base panel). So, calling clvorders.GetItemFromView(mfclvorders) outside the VisibleRangeChanged is also not possible.
    How to solve this problem?
     
    Last edited: Dec 18, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    It doesn't sound like a good approach. How many maps do you need? You should reuse the same one or two maps.
     
    eps likes this.
  3. Multiverse app

    Multiverse app Active Member Licensed User

    the number of maps is unsure. That is why we are trying to use lazy loading.
    I don't see how using 2 maps is possible. The goal is to make a list of all the 'orders' posted by users and set the location marker on each location of the order.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. Multiverse app

    Multiverse app Active Member Licensed User

    Hi Erel,
    My issue is not particularly with the map itself, but the fact that "mfclvorders_Ready " is only fired once.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Your approach is wrong. You should create two or three maps when the program starts and reuse them.
     
    eps and Multiverse app like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice