2012-07-07 88 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