Android Question Problem with tabhost with dynamically added controls

MickFinn

Member
Licensed User
Longtime User
I have a tabhost currently with two tabs. At start up I load the base layout which contains the tabhost. On the initial tab I need to add an array of edit boxes. However when I switch to the second tab, which loads another layout the edit boxes are still there, any ideas what I am doing wrong??

B4X:
Sub Globals
    Private btnCheckWinner As Button
    Private ImageView1 As ImageView
    Private lblTitle As Label
    Dim NumList As List
    Dim LottoNums(4) As EditText
    Type LottoEntry( ref As Int, Player As String, Entries As List )
    Private WebView1 As WebView
    Private ProgressBar1 As ProgressBar
    Private Exit As Button
    Dim NewList As List
    Private BtnRef As Button
    Private TabHost1 As TabHost
    Private lblStatus As Label
    Dim THExtras As TabHostExtras

    Private et As EditText
    Private NumIn As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
        Activity.LoadLayout("main")
       
    Dim bmpDefault, bmpSelected As Bitmap
      bmpDefault = LoadBitmap(File.DirAssets, "nums.png")
      bmpSelected = bmpDefault
       TabHost1.AddTabWithIcon("", bmpDefault,  bmpSelected, "lotto")

   
    Dim bmpDefault, bmpSelected As Bitmap
      bmpDefault = LoadBitmap(File.DirAssets, "whois.png")
      bmpSelected = bmpDefault
      TabHost1.AddTabWithIcon("", bmpDefault,  bmpSelected, "WhoIs")
     
   
    THExtras.setTabHeight(TabHost1, 62dip)
    THExtras.setTabHostPadding(TabHost1, 0, 0, 0, 0)
    THExtras.setTabContentViewPadding(TabHost1, 0, 0, 0, 0)
    THExtras.setTabTextColorStateList(TabHost1, "tab_widget_text_colors")   
    WebView1.Color = Colors.Transparent
        NumList.Initialize
        Dim cdb As ColorDrawable
        Dim Lft As Int
        Lft = 40
        cdb.Initialize(Colors.white, 5)
        For i = 0 To 3
            LottoNums(i).Initialize("LottoNums")
            LottoNums(i).TextSize = 46
            LottoNums(i).TextColor = Colors.Black
            'LottoNums(i).Background = cdb
            LottoNums(i).Tag = i
            LottoNums(i).InputType = LottoNums(i).INPUT_TYPE_NUMBERS
            Activity.AddView(LottoNums(i), Lft, 350, 150, 150)
            Lft = Lft + 165
        Next   
End Sub
 

klaus

Expert
Licensed User
Longtime User
In the lotto layout, add a full screen Panel with the name pnlLotto change for all the views the parent property from Activity to the pnlLotto Panel.
Then to add the EditText views in the code use pnlLotto.AddView(LottoNums(i), Lft, 350, 150, 150)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…