Android Question Help to Read values of Textbox on Runtime Created

Discussion in 'Android Questions' started by hibrid0, Jun 4, 2015.

  1. hibrid0

    hibrid0 Active Member Licensed User

    Hi guys, I'm a new with Basic4Android and have a question.
    I need to create 150 labels and 150 EditText, I create it on Runtime and the code is almost this:

    Code:
    For i = 0 To 150 -1

            
    'Inicia Agregar un Label

      labelx.Initialize(
    "labelx")
      labelx.TextSize= 
    20
      labelx.Text=
    "Un label"
    pnl_formulario1.AddView(labelx, 
    30dip, (i*30), 200dip25dip)


            
    'Inicia Agregar un Textbox
      textbox.Initialize("labelx")
      textboxTextSize= 
    20
      textbox.Text=
    "Un Textbox"

    pnl_formulario1.AddView(textbox, 
    30dip, (i*30), 200dip25dip)



        
    Next
    How can I read the .text value on each editbox to save to a SQLlite Database?
    I read from the database and put it on the Label ok, but the problem is to read the textboxes.
     
    Last edited: Jun 4, 2015
  2. DonManfred

    DonManfred Expert Licensed User

    Code:
    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Private Button1 As Button
        
    Dim arrlbl(150As Label
    End Sub
    Code:
    For i = 0 To 149
            arrlbl(i).Initialize(
    "lbl")
            arrlbl(i).TextSize= 
    20
            arrlbl(i).Text=
    "Un label "&i
            
    Activity.AddView(arrlbl(i), 30dipDipToCurrent(i*30), 200dip25dip)
        
    Next
    Code:
    Sub Button1_Click
        
    For i = 0 To 149
            
    Log(arrlbl(i).Text)
        
    Next
    End Sub
     
    hibrid0 likes this.
  3. klaus

    klaus Expert Licensed User

    The code in post# 2 will not work.
    It should be:
    Code:
    Dim lbl_fromulario1(150)
    Dim edt_fromulario1(150)

    For i = 0 To 149
        lbl_fromulario1(i).Initialize(
    "lbl_fromulario1")
        lbl_fromulario1(i).TextSize= 
    20
        lbl_fromulario1(i).Text=
    "Un label"
        lbl_fromulario1(i).Tag = i  
    ' only needed if you need events
        pnl_formulario1.AddView( lbl_fromulario1(i), 30dip, (i*30dip), 200dip25dip)

        edt_fromulario1(i).Initialize(
    "edt_fromulario1")
        edt_fromulario1(i).TextSize= 
    20
        edt_fromulario1(i).Text=
    "Un label"
        edt_fromulario1(i).Tag = i   
    ' only needed if you need events
        pnl_formulario1.AddView(edt_fromulario1(i), 130dip, (i*30dip), 200dip25dip)
    Next
    I changed the Label and EditText names like the Panel.
    And then
    Bobby = lbl_fromulario1(i).Text
    edt_fromulario1(i).Text = "anything"

    If you need events, then:
    Code:
    Sub edt_fromulario1_EnterPressed ' or any other event
        Dim edt As EditText

        
    ' you can work directly with this EditText object
        edt = Sender  ' Sender is the EditText which raised the event
        SomeVariable = edt.Text

        
    ' or wget the index
        Dim Index As Int
        Index = edt.Tag  
    ' Index of the EditText which raised the event
        SomeVariable = edt_fromulario1(Index).Text
      
       
    ' your code

    End Sub
     
    hibrid0 and inakigarm like this.
  4. hibrid0

    hibrid0 Active Member Licensed User

    Ohh thanks DonManfred, klaus a Lot!!
    I'm testing the code and work almost perfect for me.

    But in the events I have a problem

    Code:
    Dim Calendar As DateDialog
    Sub edt_R4_LongClick
          calendario.Show (
    "Seleccione""Calendario""OK""Cancelar"""Null)
          edt_R(
    4).Text=DateTime.Date(calendario.DateTicks)

    End Sub
    I try to show a data picker, in Edittext created with the designer work.
     
    Last edited: Jun 4, 2015
  5. klaus

    klaus Expert Licensed User

    Unfortunately you don't show enought code to give a concrete advice.
    What object is calendario ?
    What object is td ?
     
  6. hibrid0

    hibrid0 Active Member Licensed User

    Hi, I upload an small B4A Project
     

    Attached Files:

    Last edited: Jun 4, 2015
  7. klaus

    klaus Expert Licensed User

    I'm afraid that you are mixing up different things:
    You use Sub edt_R4_LongClick
    and then in the routine you use edt_R(4).
    These are not the same !
    As said before without seeing what you have done it's impossible to give a concrete advice !
    Couldn't you post a small project, as a zip file, showing the problem.
     
  8. hibrid0

    hibrid0 Active Member Licensed User

    I uploaded small project. Thanks for your support.
     
  9. klaus

    klaus Expert Licensed User

    Where is the project ?
     
  10. DonManfred

    DonManfred Expert Licensed User

    in #6?
     
  11. klaus

    klaus Expert Licensed User

    Sorry, I didn't look at the previous posts.

    The txt_LongClick event routine should look like this:
    Code:
    Sub txt_LongClick
        
    Dim edt As EditText
        
    Dim i As Int
       
        edt = 
    Sender    'Sender is the view which raised the event
        i = edt.Tag        'i = index of the EditText view in the txt array
        Calendario1.Show("Seleccione""Calendario""OK""Cancelar"""Null)
      txt(i).Text=
    DateTime.Date(Calendario1.DateTicks)
    End Sub
    Attached, a modified project.
     

    Attached Files:

  12. hibrid0

    hibrid0 Active Member Licensed User

    Klaus Thanks!!!
    That work perfect!!
    I'm just learning.
     
Loading...