Empty gridlines in android gridview? - android

I want a gridview with empty grid lines as follows
Here is what i got till now, gridview with gridlines in the occupied cells only. I want gridlines in empty cells also. Is this possible?

I'm almost positive a GridView was never intended for this, so you have two options.
-Write your own GridView that supports a defaulted view.
OR
-If this is not a dynamic view that is changing all the time in real time:
In your adapter, set a minimum in your getCount method (return Math.max(actualSize, minimumCount)). And set the views with no data to your empty boxes.
Make sure the count is always some mod of 4 to ensure each row will be filled beyond that.
That's just what I'm coming up with on the top of my head, there's most likely a better way to do it, but hopefully I'm moving you in the right direction.

Try putting an empy View within the empty cells of the grid.
For example, use a TextView with no text, or simply a new View().

Related

Should I use GridView or RecyclerView?

I need to create a view where products are compared (min 2, max 5). I had two thoughts:
Create a RecyclerView and each column would be a different item. On init I would have to set number of colums. The bad part is that if one item has more text and would go on another line, the whole column would move down, but others won't.
Create a gridView, but I would have to hardcode or create more cases for every amount of products.
Is there any suggestion on how to implement this view in a better way?
What you need is a GridLayout:
http://developer.android.com/reference/android/widget/GridLayout.html
Here's a useful tutorial:
http://www.techotopia.com/index.php/Working_with_the_Android_GridLayout_in_XML_Layout_Resources
A GridView however is completely unsuitable for your needs. It can only show equal width items that overflow to the next row when the width of the GridView has been filled.

GridView with section headers

Im trying to implement a GridView with section headers. I found one other question here Android GridView with categories? , however following the accepted answer gives me "header" as cells instead of the header being in its own row.
Im not sure what Im missing here (have tried the MergeAdapter too), can someone point out the nuance thats needed to implement the section headers in a GridView ?
This is not strictly possible. GridView does everything in terms of cells.
Now, you are welcome to create a set of cells that, when displayed together in a row, happen to look like a header. Presumably my MergeAdapter can handle that, though I have certainly never tried it. It will be up to you to ensure that:
the header cells are all in one row, which implies that...
empty cells go in any spaces in the preceding row, after the last "real" cell and before your header cells, and...
that you have the right number of header cells (i.e., equal to your number of columns), and...
that the header cells render correctly to look like a contiguous header, and...
that you use areAllItemsEnabled() and isEnabled() correctly, so that the header cells and the empty cells are not enabled
Try modifying the usual listview adapter to return grid cells see here

Rows and Columns layout in Android Widget

Things are simple, I want to make a widget with 4 lines and 4 rows in it, on each cell there would be a click-able image and an action set by the user via the Settings page.
The layout is like this:
What layout element is recommended to be used for this scenario ? Should I use a GridView, TableLayout, more Linearlayouts ? Keep in mind that the spacing between items must be the same. I want to make it as light as possible. So, what layout ?
If I decide to use a GridView do you have any simple tutorial about
this? I can't manage to find a way of accessing the GridView from
AppWidgetProvider and set it's Adapter. Thank you.
LE: It seems that GridView is supported starting from Android 3.0.. please correct me if I'm wrong. In this case the only remaining thing to do is add 16 images and for each image add a onClickListener ? Brrr...
If you use a GridView then half of your work is done for you - The only layout and formatting elements you need to consider are on a Global (GridView) and Item level.
Using a GridView will also give your Scrolling functionality and the ability to change your row/columns count based on your device (4x4 on tablet, perhaps 2x8 on a phone).
Creating an extension of BaseAdapter to attach the Grid's children will also give you the flexibility to check items, multi select and will allow you to quickly modify the implementation in future by adding and removing items at will.
If this is simply a 4x4 grid which will always ALWAYS remain the same independent of device and each "Item" will always be the same, Use a RelativeLayout as it will be the most lightweight and efficient ViewGroup.

ListView's contents scrambled on scroll

So I am having a problem with the different pieces of that make up my ListView. I put them into an ArrayList and use a custom ArrayAdapter to hook up to the ListView, which I have done before so I don't believe there is a problem there. Initially the list seems to have the pieces in the correct order, but then I will scroll down the list and the contents will then load in incorrect order. I then scroll back up and everything is jumbled. Has anyone run into this before?
Thanks
-Jake
Yes your problem is related to the fact that List reuses the views for each row. So say your list can see 5 items, but your ListAdapter has 15 things in it. Android will create 5 + 1 instances of your row view instead of 15. One for each row in the list + 1 for when half of the top and bottom can be seen. When a row is moved out of the visible area the List will recycle that view instance for another row instead of creating a new one. If you don't properly reset all of the user interface components every time you'll get artifacts from other rows showing up. You must make sure that every time you bind your data from the objects in your array list to the view you set every field every time.
For a better description of this see
http://www.youtube.com/watch?v=N6YdwzAvwOA&feature=related

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