开发者

Android, how to display a list of objects, one per page?

开发者 https://www.devze.com 2023-03-17 04:37 出处:网络
I need to implement an Android viewer to display a list of results (from a real estate site web query), which I have in a list property (

I need to implement an Android viewer to display a list of results (from a real estate site web query), which I have in a list property (

private List<Estate> estatesList;

)

For each item I have one image, one description, one phone number (and some more text fields). I 开发者_如何学运维would like my app to display each result, one per page, and to display the next (or previous) one on a "swipe" (or "fling"?) gesture from user.

The question is: which is the right approach? Should I use a "ListActivity"? If so, how do I bind it to my objects list? Or should I better use a ListView?


A ListActivity is a special kind of Activity that contains a ListView. Basically, a ListActivity does just provide an easier API to build an Activity around a ListView. Nevertheless, this class is a bit useless and tends to be less interesting on the long run. You should better use an normal Activity (I mean build your own class that extends Activity) and add a ListView in it.

You should learn how to use a ListAdapter to feed your ListView with some data (the list model in MVC). You got two main alternatives : using a memory adapter, or use a CursorAdapter that will pick data directly from a database.

There are many tutorials on the web to start learning ListViews. This could be a good one, among many many others.

Regards, steff


A ListActivity is just an activity that manages a ListView, so that doesn't change much. If you want to swipe sideways, you'll have to use a Gallery instead.

For the swipe, you can detect it using a GestureDetector and your view's onTouchListener. The ListView can be scrolled either using setPosition(int position) (jumps to a given position) or smoothScrollToPosition(int position).

If what you want is something like the home screen, which whole screens scrolling left/right, then you might want to use the Workspace widget. That widget isn't included in the default API, but the code is freely available :)

0

精彩评论

暂无评论...
验证码 换一张
取 消