How to page a gridviews in android? - android

I would like to create pages of gridview in android.
The page 1 will have a 3x3 set of elements.
On clicking the next button it should jump to page-2 with the next 3x3 set of elements.
Right now i have a grid of 3x3 elements and when i give a set of 12 elements, a scrollbar will appear in the right side of the gridview and the next three elements will be shown in the same page by scrolling down.
So please help on how i can implement a page of gridviews.
Thanks,
Sen

Limit the number of items you pass to the gridview adapter.
Assuming that you have an array of items, in your newInstance() method, select from that array 9 elements according to the page. Then pass that array to the gridview adapter. Also, let your getCount method in your gridview adapter return 9.
Sorry I don't give code right now, but if it isn't clear, I will provide done snippets when I have pc access.

Related

How to display more listview items in the same line?

I would like to display 2 listview items in the same line, like favourite contacts in the default phone app. I do not need a full working solution, but only a guideline what to do.
Illustration:
There is a list of favourite contacts and there are 2 contacts (illustrated only by pictures) in 1 line.
Thanks!
You can write your own adapter to handle this, or you can use a GridView.
To use the custom Adapter strategy:
Create a row layout that has space for two elements.
In xml, for whatever you now consider one 'row', make a horizontal LinearLayout that can hold two of them next to each other. That's your new definition of a row.
In your Adapter, fill each row with two elements from your data set instead of the usual 1.
Take care to handle the case where the data set only has one element left.
Your alternative is to use a GridView,

Irregular Gridview, first row with one colum, rest id the rows with two columns

I'm trying to implement an irregular gridview for my Android app. I've defined the gridview to show 2 columns but I need to show just 1 column at the first row. Is it possible using a DataAdapter?
I don't think you can accomplish this with a gridview. The adapter simple provides the data, but the view decides how to lay it out. If your requirements allow you to make the number of columns constant, then maybe you can use the gridlayout instead. I'm thinking you could try to do you layout like the google currents app.
Gridview and ListView are super useful if you have 1000's of items since it reuses views as it scrolls. If you have lots a items in your grid, then I would probably try to use the GridView or ListView to accomplish your goal. Maybe you have to get your requirement changed. Another option is to use a ListView, but sub-divide each row into 2 columns.

How to implement efficiently a gridview layout

This layout is a shelf with 3 books each row.
I current come up with gridview for displaying the books and manually add up the shelf bar. The problem occurs when there are more than 9 books and the layout is broken when scrolling the grid.
Could anyone suggest me another better way to deal with this layout. Thanks
I think you should set the background in each element (one shelf) instead of the setting the Grid container background (three shelf) ....
it's looking difficult in your case because it would has three images in a row ..So you need to try some this switch(position%3) in getView of adapter to set three different image
or
Use the ListView and Re-set the data in Array List so that each element has three books and you can make all three images clickable of that row and can make list row unclickable and unfocusable

How to create horizontal listview which is fix the count of item when display

I want to create a horizontal listview which contain many item, one item will contain a image. When user slide listview => the count of item will be fix when it display, example display only 3 or 4 image. How can I do that? Many thanks.
Edit:
I use this
to create a HorizontalList view, everything is ok but I don;t know how to make the Next and Previous button work! Any idea?
Instead of a horizontal ListView (which, as far as I know, isn't offered by the Android SDK) you can use a HorizontalScrollView. You can add the items like to any other kind of layout class.
It looks like what you are looking for is a Paginated Gallery. I have written one here.
Its still only a couple of days old but hopefully the included Activity code will get you off the ground.

how to split list view in an activity

I have a requirement that I need to display as many elements as possible in listview.
I have some 50 elements in my listview , so to display many elemnts I decided to split the listview in two parts , means half of my activity screen will display some elements and second half will display some more elements....
Please help if its possible to draw the listview in two parts, if not please let me know if ther's any aletrnative.. The data in a listview is dynamic..
I am using Android version3.2..
So it sounds like you need to implement multiple listviews within a single activity. This stackoverflow post is probably what you're looking for.

Categories

Resources