I am developing and application that will have to implement the swipe-to-refresh pattern described here. Looking at the android docs here, it is stated that:
You enable this behavior by adding the widget to your layout file as the parent of a ListView or GridView, and implementing the refresh behavior that gets invoked when the user swipes.
Well the issue is that I do not plan on having a ListView or GridView to layout my data, I am using cards (android.support.design.CardView) and I am planning on having a scrolling list of cards that the end user can swipe to refresh.
Can I still use the SwipeToRefreshLayout as described in the tutorial with my cards, or does it force me to use ListViews or GridViews to display my data?
Well as the documentation says that
The SwipeRefreshLayout should be used whenever the user can refresh
the contents of a view via a vertical swipe gesture.
This layout should be made the parent of the view that will be
refreshed as a result of the gesture and can only support one direct
child.
It does not mention that the view must be a ListView or a RecyclerView.
Also as seen in those questions:
SwiperefreshLayout in Android
Android SwipeRefreshLayout how to implement canChildScrollUp if child is not a ListView or ScrollView
Both of them have implemented a SwipeRefreshLayout with LinearLayout as the child View. So yes it will work with the view either being a CardView or a ScrollView.
Hope it helps!!!
Related
I want to know when to use ScrollView or ListView or RecyclerView and also Can we use WebView for building an app?
SCROLLVIEW
ScrollView is used to put different or same child views or layouts and the all can be scrolled.
Listview
ListView is used to put same child view or layout as multiple items. All these items are also scrollable.
Simply ScrollView is for both homogeneous and heterogeneous collection. ListView is for only homogeneous collection.
What is RecyclerView?
The RecyclerView widget is a more advanced and flexible version of ListView.
Why RecyclerView?
RecyclerView is a container for displaying large data sets that can be scrolled very efficiently by maintaining a limited number of views.
When you should use RecyclerView?
You can use the RecyclerView widget when you have data collections whose elements
changes at runtime based on user action or network events.
WEBVIEW
WebView in Android turns the application into a web application. It comes from
android.webkit.WebView. Here, the WebView class is an extension of Android's View
class which is used to show the web pages. WebView doesn't include all the features
of Web-browser-like navigation controls or an address bar etc.
I created an activity with a ListView. That is a Friend ListView.
I wanna let it choose to add it to another View.
I don't know which View to choose is the best. Recyclerview or ScrollView?
Like this
Basic difference between RecyclerView and ListView are the below.
ListView is simple to implement. Default Adapters available.
But ViewHolder pattern and finding views using ID's used to give slow performance.
Now in RecyclerView , the above problems are attended using RecyclerView.ViewHolder.
For RecyclerView adapter, this ViewHolder is mandatory. While comparing to list view this is kinda complex, but solves performance issues in ListView.
Difference LayoutManagers are available while using RecyclerView.
LinearLayoutManager
StaggeredGridLayoutManager
GridLayoutManager
Major improvement of RecyclerView performance while comparing to ListView would be this according to developer.android.com
The RecyclerView creates only as many view holders as are needed to
display the on-screen portion of the dynamic content, plus a few
extra. As the user scrolls through the list, the RecyclerView takes
the off-screen views and rebinds them to the data which is scrolling
onto the screen
To sumup, RecyclerView is preferable than ListView (when UI is having same widgets repeating according to your data)
Now when to use ScrollView:
Your UI elements may not show completely in small device screens. But in bigger screen sizes it may!
Elements may not be necessarily only list / grid. It can have combinations of any UI widgets.
Eg:- TextViews vertically , with RadioButton and Button at last for user action.
This cannot be included in ListView/ RecyclerView , now you can add ScrollView which will have a LinearLayout/RelativeLayout . Inside which all other elements can be added.
Now you can
I recommend to user always RecyclerView and never a ListView. Use RecyclerView for element list and scrollview for static views.
Seeing your image Scrollview inside RecyclerView or ListView have problems with drag.
Use a vertical RecyclerView in all page and horizontal RecyclerView each row.
I suggest you to use RecyclerView because you will load lots of images and if you use ScrollView eventually you will use so much memory. Also it is recommended to use RecyclerView when you have dynamic data. You can look the definition of the RecyclerView in the Android Documentation as follow
RecyclerView is a view for efficiently displaying large data sets by
providing a limited window of data items.
You can use nested RecyclerView for creating such hierarchal view.
You can also checkout this example for nested RecyclerView usage.
Also you can further read:
Android Recyclerview vs ListView with Viewholder
RecyclerView vs. ListView
Should we use RecyclerView to replace ListView?
I hope this helps.
Here is what I am trying to achieve:
Link to google's material design guide
In my case I have multiple cards in a scrollView, which contains a linear layout. I did not use a recycler view because the number of cards is always about the same (below 10). One of the cards contains two recyclerviews showing a list of for example comments. The problem is that I can't find a way to disable scrolling of the internal recyclerview without causing it to not scroll at all and show incomplete data.
Thanks for your help!
Use a NestedScrollView and put your RecyclerView inside it.
If you wish the RecyclerView to become a scrolling part of your NestedScrollView, set nested scrolling to false.
NestedScrollView nestedScrollView = findViewById(R.id.myNestedScrollView);
nestedScrollView.setNestedScrollingEnabled(false);
If you want an independent scroll you don't need to do anything since nested scrolling is set to true by default.
I'm creating an app that will support Android 2.2 and above.
In that I have 10 edit texts and 10 text views that I accommodate in a scroll view.
And I wanted to Accommodate a list view also inside the same activity.
Is it possible to accommodate the whole in a single activity?
You can have a ListView in a ScrollView, but that is a bad design. Even Eclipse will throw a warning. Moreover the behavior will be different, because ListView already has its own ScrollView.
So the only solution could be to have a Fixed length ScrollView and a ListView in some other Layout(Linear/Relative).
Yes, it is possible however it's not recommended enclose a list view inside a scroll view since list view has already implemented scrolling and as android documentation says it won't work. What you could do is to create a fragments, and in one fragment place a views that you want to have inside a scroll view and on other fragment - your list view. Then put two fragments inside an activity.
I have a vanilla "News" app, where the main page is a ListView that scrolls vertically with a list of articles (thumbnail, title..etc). This works just fine, but now I want to add a horizontal article/photo rotator as the top item in that list. I don't really care if it's technically in the list or not, but it should scroll up/off the screen when the list is dragged...etc. I assume(d) it should be in the list, but am quite new to Android and don't know if there's a better solution.
After an entire day of searching around, I'm still empty-handed - don't know how to add it or even if it's the right method. I'm using a ViewPager for my gallery view (when they click a photo), and that seems to be working fine...but that's the entire view... and this one already has an adapter that populates the listView... I hope I'm just over-complicating something.
TLDR:
1) Can I add a ViewPager as top item in a ListView?
2) How would one go about doing it?
3) Is there a better solution?
Note: android:minSdkVersion="8" android:targetSdkVersion="15"
You can use addHeaderView() from the ListView API to set a header. It can be any View, so also a ViewPager. I think you'll have to add it programmatically. Set the height of it correctly though.
i'm not sure i understand your question. ViewPager is a view like any other, so in your ListView's adapter's getView() method, return a view that contains a ViewPager.
ViewPager is a topic in itself, so if your problem is that you don't understand ViewPager, read these links,
http://developer.android.com/reference/android/support/v4/view/ViewPager.html
http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
if you are using API level 8, you should use the ViewPager and friends from the compatibility package.
that all being said, i wonder if you will have trouble putting a scrollable view inside a scrollable view. i know ViewPager contains code to pass off any gestures to child views if it decides it cannot handle them. i can't say if ListView has the same smarts.