Sasya Sasya - 1 month ago 7
Android Question

Tablelayout with listview

i am developing one activity in which i use list view with table lay out . I want to display 3 text (from mysql database values) in that list view ,but the problem is that the text are display slightly out of list order like

Text1 Text1 Text1 Text1 Text1 Text1
Text2 Text2 Text2 and i want this Text2 Text2 Text2
Text3 Text3 Text3 Text3 Text3 Text3


this way.. so any idea about the property of list view or text view to set it in order properly ? then plz comment...

List_row.xml

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:stretchColumns="1">
<TableRow
android:background="@drawable/table_row_bg"
>
<TextView
android:id="@+id/adapter_text_estate"
android:text="estate"
android:gravity="center"
android:textSize="8dp"
android:layout_marginRight="10sp"
android:padding="3dip" />
<TextView
android:id="@+id/adapter_text_division"
android:text="division"
android:gravity="left"
android:textSize="8dp"
android:padding="3dip" />
<TextView
android:id="@+id/adapter_text_id"
android:text="id"
android:textSize="8dp"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>


Main.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:background="#E0FFFF"
android:orientation="vertical" >

<TextView
android:id="@+id/cources_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ESTATE NAME"
android:textColor="#429ed7"
android:textSize="12sp"
android:textStyle="bold" />

<ListView
android:id="@+id/listCollege"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
android:layout_marginTop="8dp" >
</ListView>
</LinearLayout>

Answer

@Sasya try to thiscode hope this can help you, you can achieve this design without using Table layout..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3">

    <TextView
        android:id="@+id/adapter_text_estate"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:padding="5dp"
        android:text="estate"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/adapter_text_division"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:padding="5dp"
        android:text="estate"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/adapter_text_id"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:padding="5dp"
        android:text="estate"
        android:textSize="20sp" />
</LinearLayout>    </LinearLayout>
Comments