Android Question How to handle big forms

systems1

Member
Licensed User
Longtime User
Hello,

In Basic4android how can i handle big forms? eg: I have a form with 20 fields, and the screen size is 320 X 480.

How can i do this?
Please help me.

Thanks
 
Create two layout files:
On the first (asset) have your heading at the top and buttons (Save, Edit, Cancel) at the bottom with a Scrollview (svDetails) filling the rest of the area in the middle.
On the second (assetdetails) have your labels/fields that are on a panel (pnlDetails).
From your activity load them as follows:

Code: Copy
Activity.LoadLayout("asset") 
svDetails.Panel.LoadLayout("assetdetails")
svDetails.Panel.Height = pnlDetails.Height
 
Upvote 0
Hello Rolf,
Thanks for the code
I tried with this code but it show a page with a scrolling panel. not loaded the layout. here is my code
Code: Copy
Sub Globals
    Dim svDetails As ScrollView
    Dim pnlDetails As Panel   
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")   
    svDetails.Initialize(1000dip)
    svDetails.Panel.LoadLayout("assetdetails")
'    svDetails.Panel.Height = pnlDetails.Height
End Sub
 
Upvote 0
I have just had to create a form with 33 pages of questions !

I created the pages dynamically using the AHViewPager library and then dynamically adding the views to each page, giving 230 questions in total.

This is created on my Nexus 7 in approx 5 seconds, so acceptable to me and my client :-)
 
Upvote 0
@systems1

Here you are.
You must:
- set the Scrollview name in the Designer the same as in the code
- not initialize svDetails in the code
- set svDetails.Panel.Height = pnlDetails.Height

Best regards.
 

Attachments

Upvote 0
Hi Klaus,
I try to use another strategy,but I have error,Please correct for me. I don't know what I have mistake.
 

Attachments

Last edited:
Upvote 0
Both of the codes as below ,result is same,they doesn't scrolled.

Code: Copy
    svDetails.Initialize(0)
    Activity.AddView(svDetails,0,0,100%x,100%y)
    pnlDetails.Initialize("")
    svDetails.Panel.AddView(pnlDetails,0,0,svDetails.Width,svDetails.Height)
   
    For i=1 To 11
      k= ((70*i)-60)
      pnlDetails.AddView(CodeModule.EditTextCreator("EditText"&i),0,k,310dip,60dip)
    Next
    svDetails.Panel.Height=pnlDetails.Height

or

Code: Copy
pnlDetails.Initialize("")
    Activity.AddView(pnlDetails,0,0,100%x,100%y)
    svDetails.Initialize(0)
    pnlDetails.AddView(svDetails, 0, 0, pnlDetails.Width,pnlDetails.Height)
    For i=1 To 11
      k= ((70*i)-60)
      svDetails.Panel.AddView(CodeModule.EditTextCreator("EditText"&i),0,k,310dip,60dip)
    Next
    svDetails.Panel.Height=pnlDetails.Height
 
Upvote 0
I have just had to create a form with 33 pages of questions !

I created the pages dynamically using the AHViewPager library and then dynamically adding the views to each page, giving 230 questions in total.

This is created on my Nexus 7 in approx 5 seconds, so acceptable to me and my client :)

Hopefully this questionnaire is NOT to get admitted to the ER! Some might expire before answering all of the forms...
 
Upvote 0
The problems are the following:
First code:
Code: Copy
svDetails.Initialize(0)
Activity.AddView(svDetails, 0, 0, 100%x, 100%y)
pnlDetails.Initialize("")
svDetails.Panel.AddView(pnlDetails,0,0,svDetails.Width,svDetails.Height)

For i = 0 To 10
    k= i * 60dip
    pnlDetails.AddView(CodeModule.EditTextCreator("EditText" & (i + 1)), 0, k, 310dip, 60dip)
Next
pnlDetails.Height = i * 60dip
svDetails.Panel.Height=pnlDetails.Height

Second code:
Code: Copy
pnlDetails.Initialize("")
Activity.AddView(pnlDetails,0,0,100%x,100%y)
svDetails.Initialize(0)
pnlDetails.AddView(svDetails, 0, 0, pnlDetails.Width,pnlDetails.Height)
For i = 0 To 10
    k = i * 60dip
    svDetails.Panel.AddView(CodeModule.EditTextCreator("EditText" & (i + 1)), 0, k, 310dip, 60dip)
Next
pnlDetails.Height = i * 60dip
svDetails.Panel.Height = pnlDetails.Height
In both codes you missed to set pnlDetails.Height.
In both code the Panel pnlDetails is not useful.
It is usefull in systems1's example because the Panel containing the EditText views is created in the Designer.
I modified a bit the calculation of the Top value, in your calculation you should have used dip values !

I find using the small EditTextCreator routine in a separate module complicated.
You are also missing to set the Tag property to know what EditText view raises any event.

Best regards.
 
Upvote 0
Hi Klaus,
Thank you for make me clearly. I've adjusted all of 3 strategies,shown the same result. But I don't sure to know about manage the EditText view raise any event.
 

Attachments

Upvote 0
In B4A, the EditText view can raise 3 events:
- EnterPressed
- FocusChanged
- TextChanged
It is possible to add other events to an EditText with the Reflection library like Click, LongClick, Touch etc..

If you don't use any of these events you won't need the Tag propoerty.

Best regards.
 
Upvote 0
I'm only for study.
It is possible to add other events to an EditText with the Reflection library like Click, LongClick, Touch etc..

Besides of 3 strategies,Could I use custom view to do this? and then add the properties for class.
 
Upvote 0
Back
Top