I am trying to implement multi-column in ListView. Currently I have used a GridView for each row to give Column look. However I can think of one more approach of making the ListView row contain all the column Layout of Gridview and while binding iterate over the layout and assign data.
Approach #1: ListViewRow-> contains GridView
GridViewRow-> Layout for each column
Approach #2: ListViewRow contains say 12 LinearLayouts each having its own display (display wise all LinearLayouts are same). Similar to this
Which of these approaches will be good in performance terms?
Take a look at relative layout, maybe you can use it in your listviewrow
Related
I have to implement a ListView or GridView where every item will have non-uniform height/width. Also a particular item could span multiple columns. A GridView is perhaps a better candidate, but again each row has a different schematic. The attached image best describes what I want to achieve.
I am looking for ideas on how best to implement this. I am not looking for code samples, but just some guidelines.
Right now, I'm thinking of implementing a custom ListAdapter where each row is laid out in the scheme I want. Of course then I'd have to do some tricks to map list indexes to actually items in array of items (if I use and array adapter). For example, in the mockup below, the penguins will have an index of 1 in my array, but 0 in the ListView.
in these kind of structure you should use a layout in xml and add dynamic view in that layout from java file.
May be a relative Layout with ImageViews is good. It may get a bit messy for the .xml though! This seems quite interesting. Do keep us updated on which of the solutions you finally chose.
Thanks!
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.
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.
There is a requirement to have not-so-trivial dynamic list, each record of which consists of several columns (texts, buttons). It should look something like:
Text11 Text12 Button1 Button2
Text21 Text22 Button1 Button2
...
At first obvious way to accomplish that seemed to be TableLayout. I was expecting to have layout/styling data specified in res/layout/*.xml and to populate it with some dataset from java code (as with ListView, for which its possible to specify TextView of item in *.xml and bind it to some array using ArrayAdapter). But after playing for a while, all I found to be possible is fully populating TableLayout programatically. Still, creating TableRow by TableRow and setting layout attributes directly in java code doesn't seem elegant enough.
So the question is: am I at the right path? Is TableLayout really best View to accomplish that? Maybe it's more appropriate to extend ListView or something else to meet such requirements?
Using ListView and ArrayAdapter you can do more complicated layouts than just a TextView. You could specify a LinearLayout with 2 TextViews and 2 Buttons for each row in the List.
here's a similar question
Android: ListView elements with multiple clickable buttons
IMHO it depends on the amount of your data you need to render.
Build layout dinamically via inflate/addView is a quite simple task but is
also more slow than using a custom adapter. with a custom adapter you can
reuse the convertView parameter and then set the values more efficiently
I'd like to use different row descriptors (from the XML layout resource) in one ListView. Can I and how?
Also, I'd like to be able to programmatically change the size of the rows, based on the data in each row, in a ListView. Can I and how?
Thank you in advance--I LOVE stackoverflow.
M
I'd like to use different row
descriptors (from the XML layout
resource) in one ListView. Can I and
how?
Step #1: Override your Adapter class and implement newView()/bindView() (or getView() if ArrayAdapter)
Step #2: Inflate the rows you want when you want them from the layouts you want
Step #3: Override getViewTypeCount() and getItemViewType(), returning appropriate values, so Android knows to use different object pools for each distinct type of row
This book excerpt covers #1 and #2, though for only one type of row. I don't have any samples handy for multiple types of rows, sorry.
Also, I'd like to be able to
programmatically change the size of
the rows, based on the data in each
row, in a ListView. Can I and how?
Put in bigger stuff in the row. Heights of rows are determined by their contents.