How Can I add a header in gridview? - android

I want the content of my gridview seperated with headers!
We can easily accomplish this in listview!
How to do this part in a gridview?
I want the same , as the headers has to be same and the cntent of each header must be a gridview of items! Please dont see and compare the content in the image below. its just a downloaded one!
Any help?

A GridView does not have columns. It is meant to arrange a flat (without columns) array of items two-dimensionally across the screen. You should use a TableLayout, which is intented to lay out columned rows.
When you use a TableLayout, you can add a header row as your first row and then add your data rows after that. There isn't a distinction between the two.

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

Android ListView sorting problem

I want to create Gridview similar to WPF datagrid i don't know how many of you know about WPF data grid i'll explain its like having header row and rows to bind and whenever i click on each column of header row, the column 'll be sorted. But in this android list view i didn't see any header like in WPF but sorting is there and it'll sorted irrespective of column i.e. when i click on first column at row position '0' all columns 'll be sorted including header row (means header row going downwards) so how can i slove my problem?
Thanks,
#nag.
So you just want a header row in your listview? Call listView.addHeaderView() passing it the view/layout you want in the header.

Image in a custom List Android

I have created a custom adapter to display a list, there is an image that is displayed in each row ( the image is the same for all rows, except using an array i am assigning it different values depending on the position). An xml file defines the relative layout that i am using. My problem is that i can either get the entire row to be clickable or nothing at all, I only want this image to be clickable, instead of the entire row. How would i be able to do this ? i am new to android and am pretty much following different tutorials trying to create my list. Any help would be appreciated.
layout is like this :
TEXT:
[Image]
TEXT:
thats wat a row looks like...getting two texts from two different arrays and shows it, a third array is used to link to the image. I just want this image to be clickable instead of the entire row.
Thanks
Android's list component manages clicks per row. This makes it very difficult to achieve what you want to do. Two solutions come into mind:
1) If your list is never very long you could simply use linear layout and scroll view to build the list. This approach won't work if you fill in the list dynamically and you can't be sure that there won't be a very large number of rows as it would use too much memory in that case.
2) Other option is to use ListView but make your text components and images different view types in list ie. break you row into three.
That can be achieved overriding list adapter's getItemViewType(int)
http://developer.android.com/reference/android/widget/Adapter.html#getItemViewType(int)
In this approach you can make the image rows clickable but the text rows not.

Categories

Resources