iOS Question Resize Event?

ilan

Expert
Licensed User
Longtime User
hi

i normally use layouts in my apps and i load the layout and handle the resize of the layout in the resize event.

now i have a question when i want to add a new view to my layout via code do i do it in page resize event?
if so the view may be added more then once correct?

so what i do now is i remove all views in resize event and then add them.

is this the right way?

thanx
 

tufanv

Expert
Licensed User
Longtime User
Resize is the correct place to add views. I do the same as you told. Remove and re add. I am not sure if it is the correct way but works well for me.
hi

i normally use layouts in my apps and i load the layout and handle the resize of the layout in the resize event.

now i have a question when i want to add a new view to my layout via code do i do it in page resize event?
if so the view may be added more then once correct?

so what i do now is i remove all views in resize event and then add them.

is this the right way?

thanx
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Resize is the correct place to add views. I do the same as you told. Remove and re add. I am not sure if it is the correct way but works well for me.

the problem begins if you have loaded a layout and then needs to add views via code. removeallviews will also remove the layout views so we need to reload the layout.
i am not sure this is the right way.
 
Upvote 0

quimacama

Member
Licensed User
Longtime User
Hello, my app is a quiz, the questions are changing and are generated dynamically on a panel (pnlContainer).
I use that auxiliary panel that I remove and add the views.
Most questions load a layout but some depend on the answer and the size of the screen.
I have checked that if the page is already displayed it is not necessary to put the code to add the view in the Page_Resize event, but if it is the first question of the quiz, it should be put in that event.
I give an example that works for me:
B4X:
Public Sub Show
    If PagePracticar.IsInitialized = False Then
        PagePracticar.Initialize("PagePracticar")
        PagePracticar.RootPanel.LoadLayout("mnuPracticar")      
       
    End If
    Main.NavControl.ShowPage(PagePracticar)
    Play

End Sub

Private Sub PagePracticar_Resize(Width As Int, Height As Int)
     blnResized=True 
    If sAct=CNT_FRACPAINT Then
        PutImgPaint 
    End If
End Sub


Private Sub Play
    pnlContainer.RemoveAllViews 
      sAct=rnd(0,10)
    Select sAct
        Case CNT_ABCDRAGPIECE
            pnlContainer.LoadLayout("actPuzNotation") 
             InitABCNamePuz
       Case CNT_FRACPAINT
            pnlContainer.LoadLayout("actPaint") 
           InitFracPaint 
'.
'.
'.
   end select
end sub

Private Sub InitFracPaint ()
Try
    
   If bmpWhite.IsInitialized =False Then
        bmpWhite.Initialize(File.DirAssets,white.png")    
    End If
    Dim iColor As Int 
    Dim strColor As String 
    Dim arrColors () As String 
    arrColors=Array As String ("blue.png","yellow.png","red.png","pink.png")
    iColor=Rnd(0,arrColors.Length) 
    strColor=arrColors(iColor)
    bmpPintar.Initialize(File.DirAssets,strColor)  
    If blnResized=True Then  
        PutImgPaint       
    End If
   
    TGame.Enabled =True 
Catch
    Log("InitFracPaint " & LastException.Description )
End Try
End Sub

Private Sub PutImgPaint
Try 
    Dim iNumerador, iDenominador As Int 
    iDenominador =Rnd(2,11) 
    iNumerador =Rnd(1,iDenominador ) 
    iAPintar =iNumerador
    iPainted=0
   
    lblTarea.Text =modUtil.GetString("Paint","Paint ") & iNumerador & "/" & iDenominador 
      
    Dim r,c As Int 
    Dim NumberOfRows, NumberOfColumns As Int 
    Dim iNumAComparar As Int 
    If (iDenominador>5) Then
        NumberOfRows=2
        If (iDenominador Mod 2)  =0 Then
            NumberOfColumns=iDenominador/2
        Else
            NumberOfColumns=(iDenominador+1)/2  
        End If
    Else
        NumberOfRows=1
        NumberOfColumns=iDenominador  
    End If 
    iNumAComparar=iDenominador
       
    Dim flWidth, flHeight As Float 
    flWidth= pnlOption1.Width/NumberOfColumns 
    flHeight = pnlOption1.Height /NumberOfRows
    flWidth=Min(flWidth,flHeight) 
    flHeight=flWidth
       
    Dim iCreados As Int 
    For r=0 To NumberOfRows -1
        For c = 0 To NumberOfColumns - 1
            If iCreados< iNumAComparar Then 
                Dim img As ImageView  
                img.Initialize("imgPaint") 
                img.Bitmap =bmpWhite
                Dim mtagPaint As tagPaint
                mtagPaint.Initialize 
                mtagPaint.iKey =c+NumberOfColumns*r    
                mtagPaint.blnPainted =False
                img.Tag =mtagPaint 
                pnlOption1.AddView (img, c* flWidth,r*flHeight,flWidth,flHeight)  
                iCreados=iCreados+1    
            End If
        Next
    Next 
       
    pnlOption1.Left = ((pnlContainer.Width-pnlOption1.Width)/2)+(pnlOption1.Width-flWidth*NumberOfColumns)/2
   
Catch
    Log(LastException)
End Try
End Sub
 
Upvote 0
Top