• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Multiple EditText fields per row

Alex A

Lurker
Jul 26, 2009
1
0
Hi all,

I started Android development this morning, and that's pretty much what I was doing all day :)
It's very exciting and Eclipse plug in is so easy to use!!! Here's a little problem that I ran into with XML.

Trying to put 4 EditText fields in one row of a TableLayout as
follows:

Code:
<TableLayout
		android:layout_height="fill_parent"
		android:layout_width="fill_parent"
		android:id="@+id/MainText>

<TableRow
		android:id="@+id/Row1"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content">

    <TextView
        android:id="@+id/label1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/first"/>
</TableRow>

<TableRow
		android:id="@+id/Row2"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content">

    <EditText
        android:id="@+id/inputField1"
        android:layout_column="0"
        android:layout_width="30dip"
        android:layout_height="wrap_content"
        android:padding="3dip"/>

    <EditText
        android:id="@+id/inputField2"
        android:layout_column="1"
        android:layout_width="30dip"
        android:layout_height="wrap_content"
        android:padding="3dip"/>

    <EditText
        android:id="@+id/inputField3"
        android:layout_column="2"
        android:layout_width="30dip"
        android:layout_height="wrap_content"
        android:padding="3dip"/>

    <EditText
        android:id="@+id/inputField4"
        android:layout_column="3"
        android:layout_width="30dip"
        android:layout_height="wrap_content"
        android:padding="3dip"/>
</TableRow>

</TableLayout>

But what this results in is just one EditText field (the first one) taking up the whole second row. What I need is all 4 entry fields in one row.
What is the problem here?
Any help is appreciated.

Alex
 
I haven't used tables very much; I prefer to use LinearLayout -- if you nest horizontals inside a vertical, you'll get almost the same effect.

I did spot this in TableLayout, however, indicating your TableRow's need a little reviewing:
The children of a TableLayout cannot specify the layout_width attribute. Width is always FILL_PARENT. However, the layout_height attribute can be defined by a child; default value is WRAP_CONTENT. If the child is a TableRow, then the height is always WRAP_CONTENT.
This brief example mentions sizing in table cells; you seem to be on the right track there.

Hope this helps.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones