2012-07-07 36 views
0

在我的应用程序中,我有1个tablelayout和1个database.Now,我想在表格布局中显示该数据库内容。但它应该看起来像一个listview,因为我必须显示下面的条目另一种。可以在表格布局中使用listview,也可以在表格布局中设置相应列表视图中的数据库条目。Tablelayout中的Listview android

这里是我的XML结构:

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

    <TableLayout 
     android:id="@+id/tablelayout" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:paddingRight="2dip" > 

     <TableRow> 
      <TextView 

       android_layout_span="2" 
       android:layout_weight="1" 
       android:text="Income" /> 
     </TableRow> 

     <TableRow> 
      <TextView    
       android:layout_weight="1" 
       android:text="Price:"/> 

      <TextView 


       android:layout_weight="1" 
       android:text="Price:" /> 

      <ListView 
     android:id="@+id/listView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
    </ListView> 
     </TableRow> 

     <TableRow> 
      <TextView 

       android:layout_weight="1" 
       android:text="Quantity:"/> 

      <TextView 

       android:id="@+id/et_url" 
       android:layout_weight="1" 
       android:text="Quantity:" /> 
     </TableRow> 


    </TableLayout> 
</ScrollView> 

回答

1

如果你需要证明你的数据列表/像一个列表,那么你为什么想通过这种复杂的结构,使用表格布局?

在包含列表视图的活动中使用您的主list_view_layout。创建另一个xml,如list_item &在适配器中使用它来逐一显示数据。您可以在list_item的布局中根据需要使用表格布局或设计。

在这里你会得到一个更好的了解,在vogella.com

只需准备好您的数据集,创建列表&其适配器&然后在适配器中使用的数据...这就是它!

好运:-)

+0

感谢Soumyadip Das.But我的要求是我来显示表格式的数据,因为我必须证明两个列表像并排结构的一面。 – Prakash 2012-07-07 09:01:06