too many fields in an android activity - android

I have searched a lot for this but doesn't find anything helpful. My question is I have about 13 textviews with text fields as given below. I want them to be in one activity so the user can scroll down to fill all the fields. Help me how to handle this.
Name
Organization
Country
City
Contact#
Address
Zip
Amount
Duration
Card#
Currency
Expiry Date

The XML layout you are looking for is the <ScrollView> although it can have one and only one child element. This means that you will wrap your <Linear/RelativeLayout> in the <ScrollView> so that your xml will resemble:
<ScrollView>
<LinearLayout> <!-- or <RelativeLayout> -->
<!-- all of your textviews and edit texts, etc. -->
</LinearLayout>
<ScrollView>

I would use a scrollview with the textviews in it so that the user can scroll down to see the rest of the information

What about using <ScrollView>?
You just have to surround the part of your UI you want to be scrollable in the xml with a ScrollView element...
http://developer.android.com/reference/android/widget/ScrollView.html

Related

Android: Your XML document has more than one root view

I'm using XML and I'm a beginner in XML. I basically tried to put two TextViews but it shows an error. How can I resolve this?
This is a screenshot of the code and the error that is showing up:
With XML you must have a single document element. There needs to be a top level "container" for the content.
Your screenshot shows that you have two TextView elements. Effectively, two XML documents, not one.
You could choose to wrap them with a document element:
<doc>
<TextView/>
<TextView/>
</doc>
or save each of those TextView elements as their own XML file.

One "list" below another inside a ScrollView

I would like to reproduce this layout :
The blue lists are not scrollable, but the red panel (probably LinearLayout) is.
I already tried two ListView but I don't think it is the good way to do this, it doesn't work.
I read an article that advised to add multiple items to a LinearLayout. But in doing so, how to handle events on a single item, or use a BaseAdapter ?
I know I'm a little vague, but I'm having a little trouble explaining what I really want, I started Android development a few days ago.
Thanks.
I don't think it uses any ListView.
You can probably create something like this by having the red panel be a LinearLayout or RelativeLayout that's inside a ScrollView, so that it scrolls.
Then the blue "list" is probably not a ListView if it doesn't scroll. I guess it's just a bunch of regular views. So, something like this (pseudo code)
<ScrollView>
<LinearLayout>
<whatever layout for the green cell>
<include layout="blue_cell>
<include layout="blue_cell>
...
</LinearLayout>
</ScrollView>
And then you just create a layout for your blue cell, see info here: http://developer.android.com/training/improving-layouts/reusing-layouts.html
If you have a variable number of blue cells, you can just have the ScrollView and LinearLayout in XML, and inflate the blue cells layout programatically and add them to the LinearLayout

set Webview to render content with a specific amount of space at top of content

Goal:
I need some space at the top of the content as if the HTML starts off with <BR><BR><BR>
However, I don't want to inject a bunch of those manually because I need to control the amount of space in terms of DP's
How can it be done ?
Set the android:layout_marginTop="xxdp" in your webview attributes.
You can set the background of the activity to a specific color like white so it doesn't seem odd to the user, if you want to.
How I did it in my app was make a second empty LinearLayout and place it above the layout that includes the webview. For example:
<LinearLayout>
<LinearLayout>
</LinearLayout>
<LinearLayout>
//webview
</LinearLayout>
</LinearLayout>
And then I resized the first LinearLayout to a percentage in the GUI.
That's probably the absolute worst way to achieve your goal, but it worked for me.

Android: How to change Relative Layout to Scroll Layout

Hello i have an Relative Layout in Android, with EditTexts, TextViews, one Spinner and RadioButtons. It's a lot of things for only one screen, so i need to change for a ScrolView. When i try add the line in the first line and on the last Row, I have problems.
How can i add a scroll on my screen without lose all the layout I built so far?
so i need to change for a ScrolView
You do not need to change "for a ScrolView". You need to wrap your RelativeLayout in a ScrollView.
How can i add a scroll on my screen without lose all the layout I built so far?
Put a ScrollView around your RelativeLayout:
<ScrollView>
<RelativeLayout>
<!-- existing stuff here -->
</RelativeLayout>
</ScrollView>
As #CommonsWare has said, you can just wrap your current layout with a ScrollView.
Just keep in mind that a ScrollView must have only one child.

Speeding up complex Android View Inflation

I have a relatively big XML layout (38 kB, 600 lines) with hierarchy like:
<ScrollView>
<LinearLayout>
<TabHost>
<LinearLayout>
<FrameLayout> //tab widget
<LinearLayout> //tab content
<LinearLayout> //section
<TextView> //section name
<LinearLayout orientation="horizontal"> //item 1 box
<TextView> //item 1 title
<Spinner> //item 1 picker
</LinearLayout>
<LinearLayout> //item 2 box
<TextView> //item 2 title
<Spinner> //item 2 picker
</LinearLayout>
... //18 other items
</LinearLayout>
... //4 other sections with 15 items each
</>
It is a data entry form that has to have that many items and the best I can do now is to do to wrap setContentView and loading of data to the spinners in an AsyncTask with a "Loading..." dialog.
Does extensive using of themes also slow down the view inflation? The view inflater wouldn't need to look in loaded theme.xml, but if I were to inline the theme into the layout xml, it would also increase the size of the XML considerably, thus slow down the parser.
Is there something I could do to simplify the layout that would make it load at least twice as fast?
I'm thinking that I might try to get rid of the horizontal LinearLayouts, and build the "section" with TableLayout.
First, three general comments:
You really want to avoid layouts that deeply nested.
Consider using RelativeLayout to replace nested LinearLayouts.
Use the layout_opt tool to get some suggestions on layout optimizations.
Now, more on #1 … have you considered writing your own layout? It sounds complex at first, but it can sometimes drastically improve layout performance. For example, if RelativeLayout doesn't serve the purpose, you may be able to combine your Linear-Frame-Linear-Linear chain into a single custom layout.
Lastly, is there a reason your tab indicators are scrollable? That seems like a navigation/UX problem.
The only thing I can think to do would be to break your views into a couple different parts and inflate each view whenever the user gets to that part. Not sure if that helps at all but good luck.
Also might help to look at that portion of the code in traceview

Categories

Resources