Android Question Multiple Edit Boxes

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

Thank you in advance for answering this question.

Case
Multiple tables in SQLite with 20 or more fields.
Al fields may be updated by user.
I can build an Activity for each table with 20 labels and 20 edit boxes to allow user to enter changes or add new.

Is there a more efficient way to achieve this?

Any suggestions will be welcomed.
 

LucaMs

Expert
Licensed User
Longtime User
I think it's really fair to create an Activity for each table.

If the user must have the ability to edit each field, I do not think there is another way.

You could not put the label and use the Hint of TextBoxes, but I do not really like.

If the problem is the space available, you can add all in one scrollview.
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User

Thank you, Luca.

I was hoping more for a "form generator" as is available in some DBMS systems.

Best regards.

Sandy
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You can build the layout in the code onto a scrollview.
I would use only one Activity for editing and buiding the layout according to the selected table.
You can have a look at the SQLiteLight3 example in my signature, there the edit activity layout is generated in the code.
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User

Thank you, Klaus.

Luca pointed to the concept. I had thought about it, but your example embodied it. For those who are a little lazy, this is the code from Klaus:

B4X:
Sub InitEditPanel
    ' Adds the Label and EditText views onto the ScrollView panel by code
    Dim lbl(Main.ColNumber) As Label
    Dim edt(Main.ColNumber) As EditText
   
    Dim Height = 50dip As Int
    Dim VSpace = Height + 10dip As Int
    Dim lblLeft = 10dip As Int
    Dim lblWidth = 30%x - 10dip As Int
    Dim edtLeft = 30%x + 10dip As Int
    Dim edtWidth = 70%x - 20dip As Int
    Dim i As Int
   
    For i = 0 To Main.ColNumber - 1
        lbl(i).Initialize("")
        scvEdit.Panel.AddView(lbl(i), lblLeft, 10dip + i * VSpace, lblWidth, Height)
        lbl(i).Tag = i
        lbl(i).Gravity = Bit.OR(Gravity.RIGHT, Gravity.CENTER_VERTICAL)
        lbl(i).TextSize = 16
        lbl(i).Text = Main.ColAliasNames(i)
        lbl(i).TextColor = Colors.Yellow
       
        edt(i).Initialize("edt")
        scvEdit.Panel.AddView(edt(i), edtLeft, 10dip + i * VSpace, edtWidth, Height)
        edt(i).Tag = i
        edt(i).TextColor = Colors.Black
    Next
    edt(0).Enabled = False
    scvEdit.Panel.Height = 10dip + i * VSpace
End Sub

The secondary key concept is:

only one Activity for editing and buiding the layout according to the selected table

Best regards.

Sandy
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…