Android Question Delete an existing "panel" ?

HarryPottier

Member
Licensed User
pnl.RemoveAllViews = does not function
In this way "pnl" does not load any new content
So when I run the routine a second time, the first content always persists.
B4X:
Dim pnl As Panel
pnl.Initialize("mainpnl")
pnl.RemoveAllViews
pnl.Color = Colors.Black
pnl.Height = 88%y
pnl.Width = 100%x
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Your words "delete a panel to add new content" do not make sense. If you really delete the panel then it is gone. You cannot replace the content any more, but you could replace the panel with a new panel with new content. But why not just delete the content of the original panel (pnl.RemoveAllViews) and replace the content by loading another layout? There is no need to create and reinitialise a new panel.

If this does not make sense to you then post a larger segment of your coding so that you might make sense to us.
 
Upvote 0

HarryPottier

Member
Licensed User
Pardon, once again, to understand
I load this panel and fill the labels with text = (lbl.Text = GetrText(N))
In further actions the content (text) of (lbl.text) must change now.
In VB6 I would have done it like this
B4X:
For i = 1 to 33
    lbl(i).Caption = GetText(i)
next
lbl(i).Text = GetrText(i) = does not work in B4A

so I thought to reset and refill the whole panel
No matter what I do, the first filling always appears
So, how do I change the content of (lbl.Text) ?


B4X:
Sub loadinnerPanel
    Dim pnl As Panel
    pnl.Initialize("mainpnl")

    ' pnl.RemoveAllViews

    pnl.Color = Colors.Black
    pnl.Height = 100%y
    pnl.Width = 100%x
    
    Dim N As Int
    Dim MemPos As Int
    
    Dim iRed As Int
    Dim iGreen As Int
    Dim iBlue As Int

    Dim yy As Int : yy = 0
    Dim xx As Int : xx = 0

    For N = 1 To GetrAnz

        If GetrWG(N) = Main.WGClick And GetrText(N).Length > 3 Then
        
            Dim itemPnl As Panel
            itemPnl.Initialize("itemPnl")
            itemPnl.Color = Colors.Black

            Dim itempnlWidth As Float = vpw/4.11 
            Dim itempnlHeight As Float = itempnlWidth/1.3       
            Dim LayoutVal As LayoutValues
            
            Dim lbl As Label

            lbl.Initialize("")
            ' lbl.TextSize = 15

            lbl.Typeface = Typeface.DEFAULT_BOLD
            lbl.Gravity = Bit.Or(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)

            iRed = GetrColor(N).SubString2(0,3)
            iGreen = GetrColor(N).SubString2(3,6)
            iBlue = GetrColor(N).SubString2(6,9)
            lbl.Color = Colors.RGB(iRed,iGreen,iBlue)

            lbl.Text = GetrText(N)

            lbl.TextColor = Colors.White

            itemPnl.AddView(lbl,9,9,itempnlWidth,itempnlHeight)
            pnl.AddView(itemPnl,xx*itempnlWidth,yy*itempnlHeight,itempnlWidth,itempnlHeight) 'das Bild zur inneren Tafel hinzufügen

            xx = xx + 1
            If xx = 4 Then yy = yy + 1
            If xx = 4 Then xx = 0

            itemPnl.Tag = N

        End If

    Next

End Sub
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Okay - here is an example. Maybe you have got the wrong mental model of how these things work - I hope that this will help sort things out.
 

Attachments

  • buttons.zip
    8.6 KB · Views: 105
Upvote 0

HarryPottier

Member
Licensed User
Thanks for going to so much trouble.
but I cannot Understanding the program.
I require 16 panels.
I prefer it, I only have one panel and only change the content.
I have now searched this with a Log(lbl.Text)
result in the jpg

Passage (1) Shows in the Log(lbl.Text) Cola, Fanta, Sprite . . .

Passage (2) Shows in the Log(lbl.Text) Café, Espresso, Großer Café . . .

So the (lbl.text) has adopted it, see jpg , but not updated on the phone.

The phone stays with Cola, Fanta, Sprite . . .
 

Attachments

  • AB-Tabelle2.jpg
    AB-Tabelle2.jpg
    114.7 KB · Views: 102
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Sorry - you sent your first post yesterday while I was writing mine and I did not notice it until the end of the day. I attach a new example project that I hope will be more useful.

Looking at your code sample I think that there might be something wrong here ...
B4X:
Sub loadinnerPanel
    Dim pnl As Panel
    pnl.Initialize("mainpnl")
    ... ...
    pnl.Height = 100%y
    pnl.Width = 100%x

Setting pnl.Height and pnl.Width will have no effect because "pnl" has not yet been added to the activity, unless you loaded "pnl" from a layout. But if you loaded "pnl" from a layout then you must not initialise again it in the activity, otherwise you are creating a new panel! And you should not be "Dim"ing it here but in "Sub Globals". I also notice that you are adding your labels to a panel before adding that panel to "pnl" - there is no reason to do that.

You also say that you cannot do this in B4A :
B4X:
lbl(i).Caption = GetText(i)

Well, you can build arrays of views if you want to; my new example uses a list of labels rather than an array, but for the same purpose. I think that your difficulties come more form understanding how Android works rather than understanding B4A. I notice that you are switching between activities when you refresh your list - that could also be a problem, but you have not sent enough of your code for me to be sure.

Final tip - if you right-click on the Log panel you can copy it to the clipboard.
 

Attachments

  • buttons2.zip
    8.6 KB · Views: 92
Upvote 0

HarryPottier

Member
Licensed User
THANK YOU Brian for your explanations and your example program.
The example program looks very good.
It takes me a while to implement the example with my data.
 
Upvote 0
Top