How to fully replace listView/GridView with RecyclerView? - android

I've noticed that the new RecyclerView class, even though it makes things a bit cleaner, is lacking a lot of functionality that I'm familiar with:
dividers, but this can be solved by looking at this post or this one
"footerDividersEnabled"
"headerDividersEnabled"
"listSelector" , but maybe I should simply set it per view ?
"fastScrollEnabled"
"smoothScrollbar"
"textFilterEnabled"
I've also tried to find out if there is a new way to use the new class with filtering (as done with ListView by implementing Filterable). I couldn't find out if there is such a thing
"tools:listitem" , to show the items on the UI designer.
Those are what I use, but maybe there are others that I missed.
Is there any tutorial or some guidelines of how to replace each of those things?

ok, I think I've found some solutions to what I wrote about:
dividers - the links I've given can probably help (here, here and here).
"footerDividersEnabled" - probably like #1, but even if you don't have it, you could always add a divider to the layout of the footer.
"headerDividersEnabled" - same as #2.
"listSelector" - should be done to the item views .
"fastScrollEnabled" - no solution is available for this, except for this library I've found, which was an answer for my post here.
"smoothScrollbar" - should be a feature request for #5. I think it's already smooth, but I'm not sure.
"textFilterEnabled" - sadly, you need to handle it yourself. create a thread pool of size 1, or manage your own thread (or use AsyncTask, in case the work is relatively short), and let it do the filtering for you.
Filterable - same as #7
"tools:listitem" - not available, but I think you could extend from RecyclerView and add it. You will however have to put some work, as RecyclerView doesn't know how to layout the views.

No tutorials that I know of, but the sources for ListView are public! There's no better way to learn than this... For example: I recently implemented filtering just like ListView does and it work like a charm. Plus, if you do it well, you only need to do it once and can re-apply it everywhere!

I would recommend you go look at some of the library's for the RecyclerView. You can find a lot of library's at https://android-arsenal.com/.
Also you can implement your own functionality in the RecyclerView and the Adapter for the RecyclerView. Just extend the RecyclerView and build on that.
I recommend that you read the source code for the RecyclerView at https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v7/recyclerview/src/android/support/v7/widget/RecyclerView.java.

Related

Recycler View custom scrolling effects

I want to make awesome scroll effect. I've found a couple of examples:
http://lab.hakim.se/scroll-effects/
but I have no idea how to such behaviour. I consider to make it on my own, but it will be good to have a library which I can use. Just need some starting point. Any ideas?
I've used this library a few times and seemed good but seems to be in need of an update since some of the delete animations have problems. But the scrolling animations should still be good:
https://github.com/wasabeef/recyclerview-animators

Custom List View With Custom Headers Android

I have to make a custom list view with custom header, ( different text in each headers) and different number of items below each header. I have been going through various section indexing examples but I think they are not relevant much to my answer.
Anybody please suggest me a good means to move around such type of list view in android.
This might be a duplicate of Android Listview with sections
There are lots of different ones out there. One example is: http://w2davids.wordpress.com/android-sectioned-headers-in-listviews which uses: http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09
That one allows you to pass in different array adapters for each section so that you can have different layouts for each section's items.
If you were more clear about what the ones you have seen fail to do that you need it would be easier to offer you something you haven't seen.
There has been lot of thread exists on the Stackoverflow, check:
Android Listview with sections
Android ListView section header
How to draw a section header in Android listview just like the Contacts app did ?
But I am not sure these threads has helpful info, but if you want to read, understand and implement ListView with sections then here is one of the great and detailed article given by Cyril: ListView Tips & Tricks #2: Sectioning Your ListView
For a more complex design with sections in list, you should try this very standard library : https://github.com/emilsjolander/StickyListHeaders.
Other alternatives mentionned are great.
I should mention that the only drawback of this library is a poor mavenization and its absence on central.
Try this tutorial..its very nice and simple
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
There's a very good library for this. I've used in a project or 2 myself. Check it out:
https://code.google.com/p/android-amazing-listview/
Why can't you use expandable list view?
this link might help you: Android Exandable listview tutorial

Extending AbsListView example

I would like to build a custom List (Pinterest grid layout) and I would like to extend AbsListView. Are there good examples around? It seems very very difficult.
Thanks
Tobia
i've created a nice post about this and found out this is the best one.
however, do note that just like the other libraries, it has its own issues. what i've found is that when you call notifyDatasetChanged() on it, you get weird pairs of views and positions on the getView method (link here about this issue). also i've found out that it doesn't call the "onScrollChanged" method at all (link here about this issue)
even though this library is nice, i would also like to see a tutorial on extending the abdListView.

Implementing swiping between different views

I've been updating an Android app today which so far had a single TableLayout-based View. Now, I'd like to duplicate that View with another set of backing data, and use horizontal swiping to switch between both. At some point I'd also like to add a third "page" with a different TableLayout.
I haven't really found any good ways to get this going. I've been looking at http://developer.android.com/training/implementing-navigation/lateral.html, and I actually copied the code fragment for the Tabs Pattern with NAVIGATION_MODE_TABS. That results in a little dropdown widget being added to the View title in the action bar, but clicking it doesn't show the tabs I set up (with actionBar.addTab()). I'm also not sure how to set up the view (XML) code to stick the TableLayouts in there.
I should mention that I don't have to care for pre-4.0 Android for this, so compatibility is not (much of) an issue.
Try to Use ViewPager Widget you can find useful links on the web, this widget handle the horizontal swiping between views.
http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
https://github.com/JakeWharton/Android-ViewPagerIndicator
http://blog.stylingandroid.com/archives/537#
I haven't really found any good ways to get this going.
Try ViewPager. Here is an Android Developers Blog post on ViewPager: http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
Here is a small sample app using ViewPager: https://github.com/commonsguy/cw-omnibus/tree/master/ViewPager/Fragments
None of the other answers ended up helping much. However, this one is pretty good:
http://thepseudocoder.wordpress.com/2011/10/05/android-page-swiping-using-viewpager/

Which order of nested layouts is most efficient in Android

I don't think I have really ever nested more than about three levels worth of Layouts (RelativeLayout, LinearLayout, FrameLayout) in Android. I am not thinking about list items which also use a custom layout for ListView but just normal layouts for an activity.
To the point though, I was chatting with another developer about nesting layouts for a certain layout we were discussing and he seemed to think that even a few nested layouts really slowed down performance. I figured there is some truth but it cant be that much.
Does anyone have a more expert approach to this? Any input? Opinion?
Thanks.
UPDATE for those who found on Google:
The first answer below is a great resource. It looks like a lot and people seem to skip over answers like that but please check it out. Very valuable.
I guess there is no silver bullet for this but I will give you some tips:
1) Try using the tools provided with the android sdk.
I tend to analyze my layouts with hierarchyviewer and layoutopt trying to reduce the amount of View used and the height of the tree.
2) Read Romain Guy's posts about <include>, <merge> and <ViewStub>
These tags are not used often but they provide great speed "hacks".
http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/
http://www.curious-creature.org/2009/03/16/android-layout-tricks-4-optimize-part-2/
3) Use dmtracedump and measure how long does it take to inflate a view.
You can check how long it takes to inflate a view. Get an inflater and measure how long it takes to inflate each of your options.
I havent done any proper testing to support this, still, I believe that android was design to use nesting Layouts in order to provide adequate UI's to the user, its practically the only way to support multiple screens so I wouldn't really worry about which is the most efficient, just that it looks the way it should.
Any other kind of bad programming practice would probably have a bigger effect in efficiency than layout nesting.
The difference will be much more important when you use such a layout for every item in a ListView for instance. Hopefully this simple example showed you that getting to know your layouts is the best way to learn how to optimize your UI.
Can't give you a full answer, but Romain Guy has specifically stated that nested RelativeLayouts have an exponential time for measurement.
See video here at 38:08 mark
actually all of them are based on the same class..
but it would be better to use according to me as follows:
<RelativeLayout>
<LinearLayout>
<at> here we just create nested more as we wont></at>
</LinearLayout>
</RelativeLayout>

Categories

Resources