Android Question Problem updating view

Discussion in 'Android Questions' started by RB Smissaert, Jun 17, 2018.

Tags:
  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Using OSMDroid 4.1 and have a TouchOverLay to add GeoPoints to a PathOverLay.
    Both OverLays are added to a MapView, named MapView1.

    Code:
    Sub TouchOverLay1_Click(GeoPoint1 As OSMDroid_GeoPoint) As Boolean
     
        AddAreaPoint(GeoPoint1)
        
    Return(False)
     
    End Sub

    Sub AddAreaPoint(GeoPoint1 As OSMDroid_GeoPoint)
     
        
    'as there seems no way to get these back from the PathOverLay!
        PathOverLay1Points.Add(GeoPoint1)
        PathOverlay1.AddPoint(GeoPoint1)
     
    End Sub
    This works fine and the GeoPoints are added OK. Problem it doesn't show directly in the MapView.
    Moving the MapView refreshes the image and makes the path show with the new GeoPoint. Tried all sorts of constructions to fix this, Sleep(X), DoEvents (I know is deprecated and caused indeed a crash), waiting loops and also constructions with ResumableSub, but all with no good result.

    In the end I came up with this and that seems to work:

    Code:
    Sub RefreshView(oView As View)
        oView.Visible = 
    False
        oView.Visible = 
    True
    End Sub

    Sub AddAreaPoint(GeoPoint1 As OSMDroid_GeoPoint)

        
    'as there seems no way to get these back from the PathOverLay!
        PathOverLay1Points.Add(GeoPoint1)
        PathOverlay1.AddPoint(GeoPoint1)
        RefreshView(MapView1)

    End Sub
    This seems to work fine as it doens't give a flicker and updates the appearance of the MapView.
    Is there anything wrong with this approach? Are there better ways to handle this?


    RBS
     
  2. OliverA

    OliverA Expert Licensed User

    A guess. Instead of
    Code:
    RefreshView(MapView1)
    try
    Code:
    MapView1.Invalidate
     
    RB Smissaert likes this.
  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Ah, yes that is simpler and neater.
    I looked at all the methods of MapView, but but never guessed Invalidate would do a Refresh.
    Not sure why it is called Invalidate.

    RBS
     
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