Android Question Multiple panel or view

Izmirov.Yaminovich

Member
Licensed User
Longtime User
Good day, to all of you, I'm quite new with the android programming...I want to ask, how can i overcame this problem, I want to put a map,a video view and a scrollview that catch byte that have been convert to hex string....but the problem it show this error "The specified child already has a parent. You must call removeView() on the child's parent first'

This is the code....

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example Google maps
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape   
    #CanInstallToExternalStorage: False
    #AdditionalRes: C:\Program Files (x86)\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
   
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: false
   
#End Region



'Activity module
Sub Process_Globals

Dim usb As UsbSerial
    Dim astreams As AsyncStreams
    Dim conv As ByteConverter

End Sub

Sub Globals
       Dim mFragment As MapFragment
       Dim gmap As GoogleMap
       Dim MapPanel As Panel
    Dim EditText1 As EditText
    Dim EditText2 As EditText
    Dim Edittext3 As EditText
    Dim btn_location, btn_start, btn_stop, btn_send, btn_exit As Button
    Dim marker1 As Marker
    Dim ScrollView1 As ScrollView
   
    Dim vv As VideoView
    Dim label1,label2, label3, label4 As Label
    Dim tglbtn_ipcamera As ToggleButton
    Dim VideoPanel As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
   Activity.LoadLayout("main")
   MapPanel.RemoveView
   Activity.AddView(MapPanel,0 , 0 ,50%x, 50%y)
   label3.Initialize("")
    Activity.AddView(ScrollView1,0,70%x,50%x,30%y)
    ScrollView1.Panel.AddView(label3,0,0,100%x,100%y)
    label3.Color = Colors.white                ' set the Label background color
    label3.TextColor = Colors.Black
    btn_stop.Enabled = False
    btn_send.Enabled = False
   
    marker1.IsInitialized
   If mFragment.IsGooglePlayServicesAvailable = False Then
      ToastMessageShow("Google Play services not available.", True)
   Else
      mFragment.Initialize("Map", MapPanel)
   End If
  
End Sub
Sub Map_Ready

  ToastMessageShow("Map Ready", True)
   gmap = mFragment.GetMap
   If gmap.IsInitialized = False Then
      ToastMessageShow("Error initializing map.", True)
   Else
     gmap.MapType = gmap.MAP_TYPE_HYBRID
      marker1 = gmap.AddMarker(0, 0, "Hello!!!")
      Dim cp As CameraPosition
      cp.Initialize(0, 0, 20)
     
      gmap.AnimateCamera(cp)
   End If
End Sub
Sub btn_location_Click
    marker1.Remove
     marker1 = gmap.AddMarker(EditText1.text, EditText2.text, "Hello!!!")
      Dim cp As CameraPosition
      cp.Initialize(EditText1.text, EditText2.text, 20)
      gmap.AnimateCamera(cp)
End Sub

Sub btn_start_Click
    If usb.UsbPresent = usb.USB_NONE Then
        Log("Msgbox - no device")
        Msgbox("No USB device or accessory detected!", "Error")
        Log("Msgbox - returned")
        Return
    End If
    Log("Checking permission")
    If (usb.HasPermission) Then
        Msgbox(usb.DeviceInfo, "Device Information")
        Dim dev As Int
        dev = usb.Open(57600)       
        If dev <> usb.USB_NONE Then
            Log("Connected successfully!")
            btn_start.Enabled = False
            btn_stop.Enabled = True
            btn_send.Enabled = True           
            astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
       
        Else
            Log("Error opening USB port")
        End If
    Else
        usb.RequestPermission
    End If

End Sub

Sub Astreams_NewData (Buffer() As Byte)
     Dim msg As String
    msg = conv.HexFromBytes(Buffer)
   
    label3.Text = msg
End Sub

Sub btn_stop_Click
    astreams.Close
    btn_start.Enabled = True
    btn_stop.Enabled = False
    btn_send.Enabled = False   
End Sub

Sub btn_Send_Click
    astreams.Write("abcde".GetBytes("UTF8"))
End Sub

Sub btn_Exit_Click
    ExitApplication
End Sub

Sub AStreams_Error
    Log("Error: " & LastException)
    astreams.Close
End Sub
Sub Astreams_Terminated
    Log("Terminated")
    astreams.Close
End Sub
Sub tglbtn_ipcamera_CheckedChange(Checked As Boolean)
   
    If tglbtn_ipcamera.Checked = True Then
    vv.Initialize("vv")
   Activity.AddView(vv,50%x,0,50%x, 50%y)
   
    vv.LoadVideo("http","rtsp://192.168.2.12/user=admin&password=&channel=1&stream=0.sdp?")
    vv.Play
   
    Else
   
    vv.Stop
    vv.RemoveView
   
   
    End If
End Sub


And this is the android manifest

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddManifestText( <permission
          android:name="$PACKAGE$.permission.MAPS_RECEIVE"
          android:protectionLevel="signature"/>
      <uses-feature android:glEsVersion="0x00020000" android:required="true"/>)
 
AddApplicationText(<meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="AIzaSyBcYAvCzna1RBJbOFLcFkGvm38921fW-b4"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"
    />)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
'End of default text.

Please teach me how to overcame that problem
 

Attachments

  • main.bal
    6.1 KB · Views: 171

KMatle

Expert
Licensed User
Longtime User
Upvote 0
Top