Android Question UnsupportedOperationException

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
I have this error.
java.lang.UnsupportedOperationException: addView(View) is not supported in AdapterView
at android.widget.AdapterView.addView(AdapterView.java:454)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:840)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1035)

I work with UltimateListView and Google Maps.
I have a list training with maps and address, tap one time all work, tap second time work, tap next....crash




The code is:
B4X:
....
Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
    If Results.Length>0 Then
        Dim Address1 As Address
        Dim i As Int
        For i=0 To Results.Length-1
            Address1=Results(i)
            toLat =  Address1.Latitude
            toLon = Address1.Longitude
        Next
        'Lancio Google Maps dopo aver acquisito le coordinate dall'indirizzo
        'Per Google Maps


        If MapFragment1.IsGooglePlayServicesAvailable = False Then
             ToastMessageShow("Please install Google Play Services.", True)
         Else        
             MapFragment1.Initialize("Map", MapPanel)
       End If
    Else
        'Msgbox("Messaggio", "Non è stato inserito alcun indirizzo")
        ToastMessageShow("Non è stato inserito alcun indirizzo", True)
    End If
End Sub


Sub Map_Ready
   Log("map ready")

   gmap = MapFragment1.GetMap
   If gmap.IsInitialized = False Then
      ToastMessageShow("Error initializing map.", True)
   Else

   
      'gmap.AddMarker(latitudine, longitudine, "Hello!!!")
      Dim cp As CameraPosition
      'cp.Initialize(latitudine, longitudine, gmap.CameraPosition.Zoom)
      cp.Initialize(toLat, toLon, 17.0)
      gmap.MapType = 1

     
   
      gmap.AnimateCamera(cp)
      If verifica_citta <> "" Then ToastMessageShow("Clicca sul punto Rosso per ottenere il tuo itinerario...",True)
      gmap.AddMarker2( toLat, toLon, indirizzo,1).InfoWindowShown = True
   End If


End Sub
.....

Anyidea ?
Thanks
Marco
 

MarcoRome

Expert
Licensed User
Longtime User
Thank you for your response Erel.
I use last googlemaps ( CustomView ) HERE

I have in design this:

mapview.jpg


i add maps in Runtime so i have also panel, and in my code i have this:

B4X:
....
Dim MapPanel As Panel
MapPanel.Initialize("MapPanel")
LayoutPanel.AddView(MapPanel, 0, lbl.Height + 1dip, LayoutPanel.Width, 200dip)
Geocoder1.GetFromLocationName(indirizzo, 1, Null)

....


Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
If Results.Length>0 Then
Dim Address1 As Address
Dim i As Int
For i=0 To Results.Length-1
Address1=Results(i)
toLat = Address1.Latitude
toLon = Address1.Longitude
Next
'Lancio Google Maps dopo aver acquisito le coordinate dall'indirizzo
'Per Google Maps
If MapFragment1.IsGooglePlayServicesAvailable = False Then
ToastMessageShow("Please install Google Play Services.", True)
Else
   MapFragment1.Initialize("Map", MapPanel)
End If
Else
'Msgbox("Messaggio", "Non è stato inserito alcun indirizzo")
ToastMessageShow("Non è stato inserito alcun indirizzo", True)
End If
End Sub


Sub Map_Ready
Log("map ready")
gmap = MapFragment1.GetMap
If gmap.IsInitialized = False Then
ToastMessageShow("Error initializing map.", True)
Else
'gmap.AddMarker(latitudine, longitudine, "Hello!!!")
Dim cp As CameraPosition
'cp.Initialize(latitudine, longitudine, gmap.CameraPosition.Zoom)
cp.Initialize(toLat, toLon, 17.0)
gmap.MapType = 1
gmap.AnimateCamera(cp)
If verifica_citta <> "" Then ToastMessageShow("Clicca sul punto Rosso per ottenere il tuo itinerario...",True)
gmap.AddMarker2( toLat, toLon, indirizzo,1).InfoWindowShown = True
End If
End Sub
You write:
Create the map once when the program starts and hide it. Show it whenever you need to.
I have this code in a activity that i open only when i read maps. So every time you use this activity is opened, and the map is used only once
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Seem that problem is resolved... but is it possible that problem is 2 two variables declared in Global :
B4X:
Dim MapPanel As Panel
.....
Private MapPanel As Panel

??
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Hi Don, yeah i know this. This is my wrong.
But the question is .... is it possibile that with 2 declared i have this error ?
Anyway if i have 2 declared ( equal ) i think that anyway B4A see as one or no ?
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Erel. I dont understand because now is also Runtime this erroCan i send you project ? ( is only a activity that have this problem )
Why are you adding maps at runtime? You should instead hide or show the map.
Hi Erel. I have this map inside UltimateListView. For this i add maps at runtime
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
No because i have ULV with htlm text, maps and 3 button. The maps i add when HTML finish ( this is with height variable, depend document HTML that i download ) . As you can see in this movie:

HERE DROPBOX

Teh thing strain and that i have this error ONLY when i tap about one training ( 3 course ). If i tap about all training ( jumping the course number 3 ) all work. Also if i add Map in Runtime.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I didn't see any map in this video. Probably missed it. Create a single map on a panel and put it wherever you need with whatever size you like.
Sorry EREL i wrong link, THIS is right if you see movie ( between 5-10 sec ).
 
Upvote 0
Top