Michelh91
Michelh91

Reputation: 692

Android ViewFlipper to flip pages on a Listview

I have a ListView in Android that I want to split in pages that fit the size of the screen.

This is the code for listview xml:

<?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>

I know that in order to use ViewFlipper you need to have as much views (ListViews in ths case) as you need inside 'ViewFlipper /ViewFlipper' Tags.

Here's my problem: My list fills from SQL querys and you can filter it, so the list sometimes have 3 pages, sometimes have 10....

So my question is: Is there any way to dynamically generate another ListView to use ViewFlipper or... is there any way to modify the xml dinamically and add Listview tags depending on how many pages I need to show?

Upvotes: 0

Views: 868

Answers (1)

Shailendra Singh Rajawat
Shailendra Singh Rajawat

Reputation: 8242

A tricky way is to add only one listView to ViewFlipper. now reload contents of desired page on flips in same listview . this will give you not only provide you

showNext()

and

showPrevious()

effects , but also good for memory consumption , because listview itself is very optimized in terms of rendering .

Upvotes: 2

Related Questions