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
 

devlei

Active Member
Licensed User
Longtime User
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:

B4X:
Activity.LoadLayout("asset") 
svDetails.Panel.LoadLayout("assetdetails")
svDetails.Panel.Height = pnlDetails.Height
 
Upvote 0

systems1

Member
Licensed User
Longtime User
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
B4X:
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

systems1

Member
Licensed User
Longtime User
We could easier help you if you posted your project as a zip file (IDE menu Files / Export As Zip).

Best regards.

Hello Klaus,

Please see the attachment,

Thanks
 

Attachments

  • Bigforms.zip
    8.3 KB · Views: 157
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
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

klaus

Expert
Licensed User
Longtime User
@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

  • Bigforms1.zip
    8.2 KB · Views: 165
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
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

  • PleaseCorrectForMe.zip
    9.2 KB · Views: 157
Last edited:
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Both of the codes as below ,result is same,they doesn't scrolled.

B4X:
    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

B4X:
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

Harris

Expert
Licensed User
Longtime User

Hopefully this questionnaire is NOT to get admitted to the ER! Some might expire before answering all of the forms...
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problems are the following:
First code:
B4X:
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:
B4X:
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

Theera

Well-Known Member
Licensed User
Longtime User
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

  • new.zip
    9.6 KB · Views: 172
Upvote 0

klaus

Expert
Licensed User
Longtime User
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

Theera

Well-Known Member
Licensed User
Longtime User
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…