2

I'm using a ListView with an array adapter to display multiple list items. I'd like to have multiple TextView in the list item as per the picture

I'm currently using a linear layout which doesn't seem to be suitable... Would a relative layout help me achieve this?

Example code or tutorial link would be cool

Cheers ListView xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listViewTest"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

ArrayAdapter xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >


    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="89dp"
        android:layout_marginLeft="4px"
        android:layout_marginRight="10px"
        android:layout_marginTop="4px"
        android:layout_weight="0.34"
        android:src="@drawable/ic_launcher" >

    </ImageView>


    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="0.97"
        android:gravity="center"
        android:text="@+id/label"
        android:textSize="30dp" >

    </TextView>

</LinearLayout> 

I'm trying to add another textView under the existing textView using graphical layout tab in eclipse but my noobieness is getting in the way

Strokes
  • 157
  • 7
  • 23

4 Answers4

0

Follow the Link. It will Help you..

android Multiple selection ListView & Textview

And

http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

Main.xml for List action

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="785dp"
            android:choiceMode="multipleChoice" >
        </ListView>
    </LinearLayout>

And Row.xml as,..

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

<TableRow>

    <TextView
        android:id="@+id/StudNo"
        android:layout_width="50px"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="5px" />

</TableRow>
  <TableRow>
    <TextView
        android:id="@+id/StudNo"
        android:layout_width="50px"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="5px" />

</TableRow>


  </TableLayout>

and try with Customized Codes..

Community
  • 1
  • 1
MGR
  • 382
  • 2
  • 7
  • 21
0

The linked picture has only two TextViews one below another. In case your using only 2 TextViews then a vertical LinearLayout should solve the purpose. However, if you intent to use more than two Views inside your ListItem then I would recommend you to use Relative Layout as it is way more flexible in holding multiple child-views, when it comes to aligning them with respect to one another.

You can follow a very simple tutorial provided by Google here: Relative Layout

Gagan
  • 1,497
  • 1
  • 12
  • 27
0

This link uses Multiple Texts in a Single Listview...

http://publicstaticdroidmain.com/2011/12/building-a-custom-multi-line-listview-in-android/

Use the Code as follow..

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal"
    android:text="Custom ListView Example" />

<ListView
    android:id="@+id/srListView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

</LinearLayout>

and,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingTop="10dip" >

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#C20000"
    android:textSize="14sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/cityState"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/phone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>
gowri
  • 681
  • 9
  • 27
0

Make xml layout for list item which contains two textview

        **listItem.xml**

    <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:orientation="horizontal"
            android:gravity="center"
            android:layout_height="fill_parent" >
            <TextView
                android:id="@+id/textview1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black"

                android:gravity="center"
                android:text=""
                android:textAppearance="?android:attr/textAppearanceMedium" />
            <TextView
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="@android:color/black"

                android:gravity="center"
                android:text=""
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </LinearLayout>



  ///*now in set this layout in your listview using Adapter as following*/
        mlistview.setAdapter(new ArrayAdapter<String>(this,
                R.layout.spinneritem, StringArray) {

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View v = null;
                if (v == null) {
                    if (DiscountActivity.this != null) {
                        LayoutInflater vi = (LayoutInflater) DiscountActivity.this
                                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        v = vi.inflate(R.layout.listItem, null);
                    }
                }

                TextView txtview1 = (TextView) v.findViewById(R.id.textview1);
                TextView txtview2 = (TextView) v.findViewById(R.id.textview2);

                txtview1.setText("textview1");
                txtview2.setText("textview2");

                v.setTag(campaign);
                return v;
            }


        });
Ravi1187342
  • 1,247
  • 7
  • 14