2011-11-09 36 views
0

我在Android中有一個ListView,我想將它們分成適合屏幕大小的頁面。Android ViewFlipper在列表視圖上翻轉頁面

這是列表視圖XML代碼:因爲你需要內部「ViewFlipper/ViewFlipper」標籤

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
android:weightSum="1"> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:textFilterEnabled="true" 
    android:layout_height="match_parent" > 
</ListView> 

</LinearLayout> 

我知道,爲了使用ViewFlipper你需要有(在部份情況下,列表視圖)儘可能多的意見。

這裏是我的問題: 我的目錄從SQL querys罷了,你可以過濾它,所以列表有時有3頁,有時有10個....

所以我的問題是: 有什麼辦法動態生成另一個ListView使用ViewFlipper或...有沒有辦法修改xml dinamically和添加Listview標籤取決於我需要顯示多少頁?

回答

1

一個棘手的方法是隻添加一個listview到ViewFlipper。 現在在同一列表視圖中重新加載翻頁所需頁面的內容。這會給你不僅能爲您

showNext()

showPrevious()

的影響,但也有利於內存的消耗,因爲列表視圖本身在渲染方面非常優化。

+0

謝謝你隊友,這幫了我很多!這就是我一直在尋找的! – Michelh91