iOS Question CustomListview Problems

jahswant

Well-Known Member
Licensed User
Longtime User
Declare all CustomListViews as process global variables and they will work properly.
I think i don't understand this very well.

I need to make something like this.

B4X:
Sub ListViewCats_ItemClick (Index As Int, Value As Object)
    Reader.Concerned = PG.Title
    Reader.Subcat = Value
    Reader.Show
End Sub

This is my show code in reader

B4X:
Public Sub Show
    Main.NavControl.ToolBarVisible = False
    btnBack.InitializeText("Previous","Previous")
    If PG.IsInitialized = False Then
        PG.Initialize("PG")
        PG.RootPanel.LoadLayout("mainreader")
        PG.RootPanel.Color = Colors.White
        pnlContent.LoadLayout("readerlayout")
        PG.HideBackButton = True
    End If
  
    Main.NavControl.ShowPage(PG)
   
     ListViewCats.Clear

    PG.Title = "Learn Arabic" & " V " & Utils.GetVersion
  
    lblMenu.Text = Concerned
  
    lblSousMenu.Text = Subcat
  
    Timer1.Initialize("Timer1",1)
      
    ImageView1.Bitmap = Utils.ResizeImage (LoadBitmap(File.DirAssets,"play.png"),ImageView1.Width,ImageView1.Height)
  
    FillListView(Concerned,Subcat)
End Sub

First time it displays correctly but when i come for the second time.Items are not displayed correctly and the third time items are not visible at all.What are the best practices when you have to do such actions ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Use anchors in all the layouts:

SS-2016-12-06_09.37.44.png


2. The problem is here:
B4X:
ListViewCats.Add(MyPanel, 25%y,RS.GetString("id"))

You can only use percentage units inside Page_Resize event.

If you are showing text items then you can use AddTextItem.
 
Upvote 0

jahswant

Well-Known Member
Licensed User
Longtime User
See point #2 in my previous post.
Look. i've called my subs in page resize event. didn't solve.
Then i changed layout values to plain figures didn't solve too.
What are best practices when you have to do such things ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code works:
B4X:
Sub FillListView(WithConcerned As String)
  ListViewCats.Clear
   Dim SQL As  SQL = Utils.OpenDatabase("learnarabic.db",False)
   Dim RS As ResultSet
   ListViewCats.GetBase.Color = Colors.White
   RS = SQL.ExecQuery("SELECT * FROM Arabic_Categories where categories = '"& WithConcerned&"'")
   Do While RS.NextRow
   Dim MyPanel As Panel
   MyPanel.Initialize("")
   MyPanel = CreateListItem( RS.GetString("english_word"),"("&RS.GetString("transliteration_word")&")",RS.GetString("arabic_word"),ListViewCats.GetBase.Width, 30)
   Size = Size + 1
  ListViewCats.Add(MyPanel, 30,RS.GetString("id"))
   Log(RS.GetString("english_word")&RS.GetString("transliteration_word")&RS.GetString("arabic_word"))
   Loop
End Sub

Sub CreateListItem(ENText As String,TText As String,AText As String, Width As Int, Height As Int) As Panel
   Dim p As Panel
   p.Initialize("")
   p.SetLayoutAnimated(0, 1, 0, 0, Width, Height)
   p.LoadLayout("readerpnl1")
   lblEnglish.Text = ENText
   lblTrans.Text  = TText
   lblArabic.Text = AText
   Return p
End Sub
 
Upvote 0
Top