iOS Question Problem displaying pages

ciginfo

Well-Known Member
Licensed User
Longtime User
With this code, I display Layout "Menu" with the BtnMenu button, then from Layout Menu I display Layout "Listing" with the BtnListing button.
If I return to the Layout "Menu" using the back button, then I return to the Layout "Listing" with the BtnListing button it bugs. I think there is an initializing problem but I don't see where.
Can you help me?
Thank you
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#End Region

Sub Process_Globals
    Public NavControl As NavigationController
    Private Page1, Cherche, Listing, Menu As Page
    Private LblCherche, LblBJ, LblLayoutMain As Label
    Private BtnCherche As Button
    Private segmentedcontrol1 As SegmentedControl
    Dim ClvListing As CustomListView
    Private hd As HUD
    Private Downloader As ImageDownloader
    Dim LISTING_LIST As String
End Sub
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "SittingBreak"
    Page1.RootPanel.Color = Colors.Blue
    NavControl.ShowPage(Page1)
    Page1.RootPanel.LoadLayout("Main")

    Cherche.Initialize("Cherche")
    Cherche.RootPanel.LoadLayout("Cherche")
   
    Menu.Initialize("Menu")
    Menu.RootPanel.LoadLayout("Menu")
   
End Sub

Sub BtnCherche_Click

    Cherche.Title = "Cherche"
    LblBJ.Text = "Bonjour"
    segmentedcontrol1.BringToFront
    NavControl.ShowPage(Cherche)
End Sub
Sub BtnListing_Click
    Listing.Initialize("Listing")
    Listing.RootPanel.LoadLayout("Listing")
   
    Listing.RootPanel.Color = Colors.ARGB(255,109,237,199)'(255,255,0,0)
    Listing.Title = "Listing"
    ClvListing.Initialize(Me, "clvListing", 100%x)
    Listing.RootPanel.AddView(ClvListing.AsView, 0, 0, 100%x, 50%y)
    ExtraitListePardistance
   
    NavControl.ShowPage(Listing)
End Sub
Sub BtnMenu_Click

    NavControl.ShowPage(Menu)
End Sub
Sub CreateListItem3(Text1 As String, Text2 As String, Text3 As String, ImgPath As String, Width As Int, Height As Int) As Panel
     'Routine pour placer 2 labels dans l'item de la customListView
    Dim P As Panel
    P.Initialize("")
    P.Color = Colors.White
   
    Dim lbl1, lbl2, lbl3 As Label
   
    lbl1.Initialize("lbl1")
    lbl1.TextAlignment = lbl1.ALIGNMENT_LEFT
    lbl1.Text = Text1
    lbl1.Font = Font.CreateNew(22)
   
    lbl2.Initialize("lbl2")
    lbl2.TextAlignment = lbl2.ALIGNMENT_LEFT
    lbl2.Multiline= True
    lbl2.Text = Text2
    lbl2.Font = Font.CreateNew(16)
   
    lbl3.Initialize("lbl3")
    lbl3.TextAlignment = lbl2.ALIGNMENT_LEFT
    lbl3.Multiline= True
    lbl3.Text = Text3
    lbl3.Font = Font.CreateNew(18)
   
    Dim ImgVignette As ImageView
    ImgVignette.Initialize("ImgVignette")
    Dim Repertoire = File.DirAssets As String
   
    P.AddView(ImgVignette, 10dip, 5dip, 18%x, 18%x )
    P.AddView(lbl1, 10dip + 20%x, 0dip, 75%x, Height/2-5dip )
    P.AddView(lbl2, 10dip + 20%x, lbl1.Height, 75%x, Height/2)
    P.AddView(lbl3, 10dip + 20%x, (lbl1.Height +lbl2.Height)-5dip, 75%x, Height/2)
    Return P
   
   
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then           
   
       
    Select Job.JobName
        'XXXXXXXXX LISTING XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        Case LISTING_LIST
    'Downloader.Initialize
            Dim RES, RES2 As String
            RES = Job.GetString

            Dim parser As JSONParser
            parser.Initialize(RES)
            Dim Affiche_list As List
            Affiche_list = parser.NextArray 'returns a list with maps
                For i = 0 To Affiche_list.Size - 1
                    Dim sb As StringBuilder
                    Dim M As Map
                    M = Affiche_list.Get(i)
                    Dim   Civilite, Prenom, Ville, Zip As String                   
                    '----------------------------------------------------------------------------------
                    Civilite = M.Get("civilite")
                    Prenom = M.Get("prenom")
                    Ville = M.Get("ville")
                    Zip = M.Get("zip")
                ClvListing.Add(CreateListItem3(Civilite, Prenom, Ville, Zip,ClvListing.AsView.Width, 55dip), 70dip, M)   
                Next
        End Select
       
    Else
        Log("Error: " & Job.ErrorMessage)
        hd.ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
       
   
End Sub
Sub ExtraitListePardistance
    ExecuteRemoteQuery("SELECT ID, civilite,  prenom,  ville, zip FROM kindasitters ",LISTING_LIST)            
End Sub

Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("http://www.xxxxxxxx.com/xxxxxxxx/connection.php", Query)'
End Sub
Sub SegmentedControl1_IndexChanged (Index As Int)
Select Index
    Case 0
        Cherche.RootPanel.Color = Colors.Green
        Cherche.Title = "Cherche"
        LblBJ.Text = "Bonjour"
        segmentedcontrol1.BringToFront
        NavControl.ShowPage(Cherche)
    Case 1
        Cherche.RootPanel.Color = Colors.Yellow
        Cherche.Title = "Cherche"
        LblBJ.Text = "Bonsoir"
        segmentedcontrol1.BringToFront
        NavControl.ShowPage(Cherche)
End Select
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   
End Sub

Private Sub Application_Background
   
End Sub
 

Attachments

  • Pages3.zip
    11.7 KB · Views: 279

ciginfo

Well-Known Member
Licensed User
Longtime User
Yes but In fact it is not the real problem. If i add "Private LISTING_LIST = "listing_list" As String" for exemple the problem is when I come many times on the "layout Listing.
The first time I display the "layout Listing", displaying is OK. But if I come back to "LayoutMenu" using the back button then display "layout Listing" a 2nd or 3th time, displaying is not OK, the listing in the customListView is incomplete or doubled. Do you think Initializing my pages is correct in my code?
thank you
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
I simplify my question with this new code.
I'm on "Layout MENU". I press the button "Vers listing" and I display "Layout LISTING" with my CustomListView (image1 joined)
1st question: How to do that CustomListView occupies the entire height of the page
2nd question: If I return to "Layout MENU" with the back buttom and display one more time "Layout LISTING", I get sometimes the image1 (attached) Sometimes the image2 (attached) if i repeat several times this action. Why? See essai.zip uploaded.
Thank you
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#End Region

Sub Process_Globals
    Public NavControl As NavigationController
    Private Page1, Cherche, Listing, Menu As Page
    Private LblCherche, LblBJ, LblLayoutMain As Label
    Private BtnCherche As Button
    Private segmentedcontrol1 As SegmentedControl
    Dim ClvListing As CustomListView
End Sub
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "SittingBreak"
    Page1.RootPanel.Color = Colors.Blue
    NavControl.ShowPage(Page1)
    Page1.RootPanel.LoadLayout("Main")

    Cherche.Initialize("Cherche")
    Cherche.RootPanel.LoadLayout("Cherche")
   
    Menu.Initialize("Menu")
    Menu.RootPanel.LoadLayout("Menu")
   
End Sub

Sub BtnCherche_Click
    Cherche.Title = "Cherche"
    LblBJ.Text = "Bonjour"
    segmentedcontrol1.BringToFront
    NavControl.ShowPage(Cherche)
End Sub
Sub BtnListing_Click
    Listing.Initialize("Listing")
    Listing.RootPanel.LoadLayout("Listing")
    Listing.RootPanel.Color = Colors.ARGB(255,109,237,199)'(255,255,0,0)
    Listing.Title = "Listing"
    ClvListing.Initialize(Me, "clvListing", 100%x)
    Listing.RootPanel.AddView(ClvListing.AsView, 0, 0, 100%x, 50%y)
    essai
    NavControl.ShowPage(Listing)
End Sub
Sub BtnMenu_Click
    NavControl.ShowPage(Menu)
End Sub
Sub CreateListItem3(Text1 As String, Text2 As String, Text3 As String, Vignette As String, Width As Int, Height As Int) As Panel
     'Routine pour placer 2 labels dans l'item de la customListView
    Dim P As Panel
    P.Initialize("")
    P.Color = Colors.White
   
    Dim lbl1, lbl2, lbl3 As Label
   
    lbl1.Initialize("lbl1")
    lbl1.TextAlignment = lbl1.ALIGNMENT_LEFT
    lbl1.Text = Text1
    lbl1.Font = Font.CreateNew(22)
   
    lbl2.Initialize("lbl2")
    lbl2.TextAlignment = lbl2.ALIGNMENT_LEFT
    lbl2.Multiline= True
    lbl2.Text = Text2
    lbl2.Font = Font.CreateNew(16)
   
    lbl3.Initialize("lbl3")
    lbl3.TextAlignment = lbl2.ALIGNMENT_LEFT
    lbl3.Multiline= True
    lbl3.Text = Text3
    lbl3.Font = Font.CreateNew(18)
   
    Dim ImgVignette As ImageView
    ImgVignette.Initialize("ImgVignette")
    Dim Repertoire = File.DirAssets As String
   
    ImgVignette.Bitmap = LoadBitmap(Repertoire , Vignette)

    P.AddView(ImgVignette, 10dip, 5dip, 18%x, 18%x )
    P.AddView(lbl1, 10dip + 20%x, 0dip, 75%x, Height/2-5dip )
    P.AddView(lbl2, 10dip + 20%x, lbl1.Height, 75%x, Height/2)
    P.AddView(lbl3, 10dip + 20%x, (lbl1.Height +lbl2.Height)-5dip, 75%x, Height/2)
    Return P
   
   
End Sub

Sub essai

Dim   Civilite, Prenom, Ville, MyVignette As String   
    Civilite = "Dr"
    Prenom ="François"
    Ville = "Duchock"
    MyVignette = "kinda.png"
For i = 1 To 6
    Dim sb As StringBuilder
    sb.Initialize
    ClvListing.Add(CreateListItem3(Civilite, Prenom, Ville, MyVignette,ClvListing.AsView.Width, 55dip), 70dip, sb)   
    Next
End Sub
 

Attachments

  • Image1.PNG
    Image1.PNG
    54.3 KB · Views: 274
  • Image2.PNG
    Image2.PNG
    24.2 KB · Views: 287
  • essai.zip
    8.7 KB · Views: 287
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Export as zip does not take the image file "kinda.png" from file folder. I join it with the zip, to place into the file folder.
 

Attachments

  • essai_03.zip
    8.7 KB · Views: 276
  • kinda.png
    kinda.png
    1.3 KB · Views: 258
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Go to the files tab and press on the sync button. It will add all files to the project.

You should handle the resize event and set the size of the custom list view:
B4X:
Sub Listing_Resize (Width As Float, Height As Float)
   ClvListing.SetSize(Width, Height)
End Sub

Note that your current code creates a new page each time. I don't know whether this is on purpose or not.
I recommend you to see this example: https://www.b4x.com/android/forum/threads/multiple-pages-example.48170/#content
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Thank you very much for your still effective assistance.
The page-Resize command is generally obscure to me. Is there a tutorial on detailed Page_Resize?
Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
See this tutorial: https://www.b4x.com/android/forum/threads/layouts-pages-and-viewcontrollers.45942/#content

The Resize event is very important in B4i. This is one of the main differences between B4A and B4i. In B4A the activity is destroyed and created when the orientation changes. In B4i the page is never implicitly destroyed. Instead the Resize event is raised to allow you to reposition your views (usually automatically by the designer).
 
Upvote 0
Top