简体   繁体   中英

Listview items not displaying the retrieved columns from database vertically

Using simple cursor adapter I retrieve 5 columns from a table using cursor query and display them using a listview. Everything goes well but the columns retrieved are displayed horizontally in the listview. I want them to be displayed one below the other like: TX_UID TX_NAME TX_AMOUNT TX_PARTICULARS

AND NOT LIKE (Displayed as of now): TX_UID TX_NAME TX_AMOUNT TX_PARTICULARS

String[] from = new String[]{  vivzHelper.TX_UID,     
vivzHelper.TX_NAME,vivzHelper.TX_AMOUNT,vivzHelper.TX_PARTICULARS};
int[] to = new int[] 
{R.id.textView,R.id.textView2,R.id.textView3,R.id.textView5 };
SimpleCursorAdapter cursorAdapter;
cursorAdapter = new SimpleCursorAdapter(getBaseContext(),  
R.layout.customgetalltxrowforeditordelete , c , from , to , 0);
thislist.setAdapter(cursorAdapter);
thislist.setAdapter(cursorAdapter);

XML Layout:

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="35dp"
android:fastScrollEnabled="false"
android:divider="#FFCC00"
android:dividerHeight="2px"
android:smoothScrollbar="true"
android:background="@drawable/my_selecter"
/>

columns retrieved are displayed horizontally in the listview. I want them to be displayed one below the other

Problem is related to customgetalltxrowforeditordelete layout instead of ListView . To show TextView's in ListView row Vertically. use LinearLayout with orientation attribute to vertical

In your customgetalltxrowforeditordelete xml file you need to do something like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
    android:id="@id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:src="@drawable/badge13"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:id="@id/textView2"
    android:layout_below = "@id/textView"

   />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@id/textView3"
    android:layout_below = "@id/textView2"
    />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@id/textView4"
    android:layout_below = "@id/textView3"
    />

you need to use layout_below attribute in your TextView providing top view's id in attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM