Hi how can i implement a list with section divider like the one on android's building blocks lists
Can you point any articles or tutorials to achieve this?
I implemented a possible version here:
http://steprobe.wordpress.com/2013/03/29/google-building-blocks-style-listview-for-android/
There are many tutorials to get grouped lists. The trick is to look for "adapter" and not "list". For instance, this one: http://android.cyrilmottier.com/?p=440
Each row in your list can be totally separated in terms of layout from others. So if you got 3 rows on your list, you can have each one can look totally different. You need to write your own adapter (i.e. extending ArrayAdapter), override getView(), getViewTypeCount() and getItemViewType(). Then for each row your getView() shall do any logic you want, inflate any layout you want and return that View to the list.
Related
My problem is simple: I need to make a layout similar to android.R.layout.simple_expandable_list_item_1 which can fit more than one textview in the layout, as well as show the little '>' symbol that indicates that the tab is expandable.
How can this best be accomplished? My first thought was to use the layout as a background of a linear layout with two textviews in it, but I can't seem to make that work.
Vogella has a pretty good tutorial on how to achieve custom list views through Adapters.
Basically, what you do is you create a Layout with the looks you want for the list items and then you extend an adapter (ArrayAdapter for instance), see section 4. Then, in your activity, you create an instance of your Adapter implementation and populate it from an Array containing the data for the list.
Also have a look at the Developers site for how to make the list scroll smoothly with the ViewHolder pattern.
And if you feel you need more info on the expandable part maybe the hive can help.
I am working on a Android project having a list view where every row shows up like a card. Hence I created separate views for each of its row.
How do I handle these multiple views in adapter Class?
Is there any code design pattern that help separately handling these views?
Thank in advance
you should use typeCount inside your adapter. here is android documentation
Your adapter needs to implement getItemViewType() and getViewTypeCount() methods to let listview handle different types of layouts per row properly. See docs: http://developer.android.com/reference/android/widget/BaseAdapter.html
I would use a recycler view. A good example of one is here
Hi I just watch the last video of Android Design in Action: Collections and I would like how do you approach the following view:
The first thing that I though was use a GridView, but how do you achieve the first item fill two items size?
The other solution that I think is use a normal ListView, but in each row return two items view. And for the first row return a single item.
What do you think about these two approach? There are a better options?
UPDATE:
I want to inflate the collection dynamically from a Cursor or a List.
Check out the link..
http://www.androidviews.net/2013/01/pinterest-like-adapterview/
in that link have Staggeredgridview example with source code try that..
https://github.com/maurycyw/StaggeredGridViewDemo
Not exactly the same scenario, but you may find this post useful.-
Create gridlayout.
Let me help you my friend. Use the following library https://github.com/Utopia-Developers/StaggeredGridView Its an implementation of StaggeredGridView that allows you to set column span on each view in the getView() method of your adapter.
I want to make a ListView like the one below. The ListItems will be grouped into sections and different sections have different item count. how do i get started??
N.B. I want the section headers on the side. i may also mention the items are queried from the database and sections are for now calculated based on a column in the table.
I think i have found something exactly what you need.
You need to implement separate adapters for sectionItem and EntryItem in this particular example which i am showing you.
Presuming that you know how to handle adapters and ListItems (customised with your own item.xml), this is a full fledged tutorial for how to make sections and entries.(Solution #2)
In the tutorial,the code to xml layout is also given but you may make your own custom layout for the section and entryitems.Its pretty easy and straightforward.
So that it will come off like this:
Use expandable listViews, here is example http://android-adda.blogspot.in/2011/06/custom-expandable-listview.html and for more info refer http://developer.android.com/reference/android/widget/ExpandableListView.html
You should use ExpandableListView
here also some examples:
Link1 Link2
I want to generate a ListView that has some dividers between some of the entries, like it can be seen in some of the property sections. See the example below. I try to generate a List that consists of some textviews followed by one of the fancy dividers explaining the next part of the list and then again some text views. How can this be done? I thought about creating different views to add to the list? Is this the way to go?
I got a solution. I don't know if it is the best one.
I use a custom adapter derived from ArrayAdapter for the list as described in this tutorial. In the adapter class I check if the position in the getView method is a normal row, then I inflate the row layout. If it is the first row from a new group I inflate a headline layout that is a normal row plus the group headline above it.
If you don't want to mix the header into one of your rows. Consider the following solution:
You can overwrite the two methods getItemViewType and getViewTypeCount.
You now have a list that can display different rows. You need to check the expected view type for the item in the getView Method and inflate different layouts depending on it.
The list will handle the recycling for you in a way that it will return only correct recycle views to your getView method, this means if the recycleView is not null it can be used to display your current cell.
You can use my SectionedAdapter, if GPLv3 is acceptable (licensed that way due to some upstream code). You can use my MergeAdapter, if you need something more flexible and with a less-limiting license (Apache 2).
I think you might be looking for android.widget.ExpandableListView
http://developer.android.com/reference/android/widget/ExpandableListView.html
I'm also interested in an answer to this. There must be a more straightforward way to do this.
In looking at the Adapter, there's a method, Adapter.getItemViewType(int position).
ListView defines a return value, ITEM_VIEW_TYPE_HEADER_OR_FOOTER which indicates if the returned item is a header or footer.
I haven't tried it, but I assume if you create your own Adapter and return an item with the type indicating it is a header or footer, that the ListView will display it appropriately.