How to force line break in xml when using a list adapter

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to force line break in xml when using a list adapter

Postby schrotti08 » Mon Jul 13, 2009 6:39 pm

I am struggling with applying a forced line break in the xml layout
when using a simple list adapter. The data for the list adapter is
being pulled from an sqlite db.

Here is the code:


SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.item, cursor, FROM, TO);
setListAdapter(adapter);


It should look like this - how can I build this in xml / or even in the java code?
---------------------------------------------------------------------------­­------------
Widget1 Widget 2 Widget 3 <= FORCED LINE BREAK
SHOULD COME HERE
Widget3 Widget4 Widget5 W6 W7 W8 W9 W10 W11 W12
---------------------------------------------------------------------------­­------------
Widget1 Widget 2 Widget 3 <= FORCED LINE BREAK
SHOULD COME HERE
Widget3 Widget4 Widget5 W6 W7 W8 W9 W10 W11 W12
---------------------------------------------------------------------------­­------------
Widget1 Widget 2 Widget 3 <= FORCED LINE BREAK
SHOULD COME HERE
Widget3 Widget4 Widget5 W6 W7 W8 W9 W10 W11 W12
---------------------------------------------------------------------------­­------------
...............
---------------------------------------------------------------------------­­------------


And here is the R.layout.item xml:


<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="4sp">
<TextView
android:id="@+id/widget1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/widget2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" : "
android:textSize="15sp"
android:textStyle="bold"
android:layout_toRightOf="@id/widget1" />
<TextView
android:id="@+id/widget3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:layout_toRightOf="@id/widget2" />
<TextView
android:id="@+id/widget4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textSize="15sp"
android:layout_toRightOf="@id/widget3" />
<TextView
android:id="@+id/widget5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:layout_toRightOf="@id/widget4"/>
<TextView
android:id="@+id/widget6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" : "
android:textSize="15sp"
android:textStyle="bold"
android:layout_toRightOf="@id/widget5" />
<TextView
android:id="@+id/widget7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:layout_toRightOf="@id/widget6"/>
<TextView
android:id="@+id/widget8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" ("
android:textSize="15sp"
android:layout_toRightOf="@id/widget7" />
<TextView
android:id="@+id/widget9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_toRightOf="@id/widget8"/>
<TextView
android:id="@+id/widget10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" : "
android:textSize="15sp"
android:layout_toRightOf="@id/widget9" />
<TextView
android:id="@+id/widget11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_toRightOf="@id/widget10"/>
<TextView
android:id="@+id/widget12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=")"
android:textSize="15sp"
android:layout_toRightOf="@id/widget11" />


</RelativeLayout>
schrotti08
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 13, 2009 6:34 pm

Top

Postby nmc » Mon Jul 13, 2009 10:13 pm

It should look like this - how can I build this in xml / or even in the java code?
---------------------------------------------------------------------------­­------------
Widget1 Widget 2 Widget 3 <= FORCED LINE BREAK
SHOULD COME HERE
Widget3 Widget4 Widget5 W6 W7 W8 W9 W10 W11 W12
---------------------------------------------------------------------------­­------------

Of course this is possible in XML: just dont tell the inflater to put widget4 layout_toRightOf widget3 if you want widget4 to appear layout_below widget1 :wink:
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby schrotti08 » Tue Jul 14, 2009 10:08 am

Oh yes! Well you can probably see that I am a true novice in this domain - but your answer was very helpful and I got it working in the meantime. Appreciate that! ch.
schrotti08
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 13, 2009 6:34 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests