简体   繁体   English

Listview项目不垂直显示从数据库中检索到的列

[英]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. 使用简单的游标适配器,我使用游标查询从表中检索了5列,并使用列表视图显示它们。 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 我希望它们显示在另一个下方,例如:TX_UID TX_NAME TX_AMOUNT TX_PARTICULARS

AND NOT LIKE (Displayed as of now): TX_UID TX_NAME TX_AMOUNT TX_PARTICULARS 不喜欢(截至目前显示):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: XML布局:

<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 . 问题与customgetalltxrowforeditordelete布局有关,而不是ListView To show TextView's in ListView row Vertically. 在ListView行中垂直显示TextView。 use LinearLayout with orientation attribute to vertical 结合使用LinearLayoutorientation属性为vertical

In your customgetalltxrowforeditordelete xml file you need to do something like this 在您的customgetalltxrowforeditordelete xml文件中,您需要执行以下操作

<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. 您需要在TextView中使用layout_below属性,以在属性中提供顶视图的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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