Store panel in a map

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hello,

I'm wondering the following:
I'm having a panel which have some imageviews attached to it.
If i store the panel in a map, and call it back later, does the attached views gets lost?

When i do some logging after returning the panel, it seems that number of views = 0, but i can still keep the tag and other stuff of the panel.

Note that i'm using a class to store the panel to a map and also restore it from the same class.

Tomas
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
I'm storing and retrieving the panels in the map as following:

B4X:
'Add a new strip
Sub btnAddStrip_Click
   'Declaration of panel to add
   Dim left, top, width, height As Int
   Dim iv As ImageView
   iv.Initialize("ivStrip")
   vw = iv
   iv.Tag = strips
   iv.Color = Colors.White
   iv.Bitmap = LoadBitmap(File.DirAssets, "tempStrip.png")
   iv.Gravity = Gravity.FILL
   strips = strips+1
   left = 10dip
   width = 240
   height = 150
   top = svStrips.Panel.NumberOfViews*(height+imgSpace) + 55dip
   
   'Add the panel to the scrollview
   svStrips.Panel.AddView(iv, left, top, width, height)
   
   'Set scrollview panel
   If svStrips.Panel.NumberOfViews >4 Then
      svStrips.Panel.height = svStrips.Panel.height + (height+imgSpace)
   End If
   
   SelectedStrip = iv.Tag

   'Saves the current canvas to a map.
   mapPanels.Put(iv.Tag, pnlCanvas)
   
   ClearPanelCanvas
End Sub

'Show the options for the strips
Sub ivStrip_Click
   vw = Sender
   ac2.show(vw)
   ClearPanelCanvas
   LoadPanelCanvas(vw.Tag)

End Sub

'Clears the canvas panel
Sub ClearPanelCanvas
   For i = pnlCanvas.NumberOfViews-1 To 0 Step -1
      pnlCanvas.RemoveViewAt(i)
   Next

End Sub

'Loads the panel belonging to the strip
Sub LoadPanelCanvas (index As Int)
   Dim pnl As Panel
   pnl = mapPanels.Get(index)
   pnlCanvas = pnl
End Sub

This keeps me loading a white panel after clicking a strip.

According to thedesolatesoul:

‹tds› i think the problem is
‹tds› that when you store the pnlCanvas in the map...it doesnt store the whole object
‹tds› just a reference to the object
‹tds› or later when you change pnlCanvas
‹tds› the reference in the map points to the same variable
‹tds› so the canvas inside the map changes too!

Is this correct, and so how would i solve this?

Tomas
 
Last edited:
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
The Panel inside the Map will not change. Your code looks a bit strange. You are not creating a new panel in btnAddStrip_Click.

I have one big main panel (pnlCanvas) where the user is able to draw one or place an imageview on it.
I got smaller imageviews (called strips) at the right of the pnlCanvas.
When i create a new strip, or I save a strip, it will save the panel with the tag of the strip.

B4X:
'Saves the current canvas to a map.
    mapPanels.Put(iv.Tag, pnlCanvas)

When I click a strip, it will first clear the pnlCanvas and then loads the panel according to the tag of the strip.

B4X:
'Loads the panel belonging to the strip
Sub LoadPanelCanvas (index As Int)
   Dim pnl As Panel
   pnl = mapPanels.Get(index)
   pnlCanvas = pnl
End Sub

http://php.olvgroeninge.be/~sac.26A-07/B4A/IMG_20120724_205019.jpg

This is what i mean with the strips (right) and the pnlCanvas (left)
I hope i made this a little more clearer.

Tomas

Edit:

I've managed to fix it using types, but i'm resulting in a StackOverflowError.
Why does this happen? Do I have too many view? how can i resolve this?
 
Last edited:
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
This is the log:

** Activity (comiccreator) Resume **
java.lang.StackOverflowError
at android.text.TextLine.handleRun(TextLine.java:972)
at android.text.TextLine.measureRun(TextLine.java:416)
at android.text.TextLine.measure(TextLine.java:295)
at android.text.TextLine.metrics(TextLine.java:269)
at android.text.Layout.getLineExtent(Layout.java:942)
at android.text.Layout.draw(Layout.java:405)
at android.text.BoringLayout.draw(BoringLayout.java:400)
at android.widget.TextView.onDraw(TextView.java:5040)
at android.view.View.draw(View.java:10983)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)


at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.ViewGroup.drawChild(ViewGroup.java:2885)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.ViewGroup.drawChild(ViewGroup.java:2885)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.widget.FrameLayout.draw(FrameLayout.java:450)
at com.an

I don't know when it exactly happening and I cannot seem to find out how to debug it.
It happens a while after i'm adding new strips and importing new bitmaps.
I don't know in which sub it occurs or on what line.

Tomas
 
Last edited:
Upvote 0
Top