This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
ViewPager PagerAdapter not updating the View
I'm new to Android. The first thing I've decided to do is Calendar. I want to display one day's events loaded from Database on each screen (via GridView component). Sliding left is previous day's events. Sliding right is next day' events.
I've looked for some examples of pagers, such as RealViewSwitcher or Deezapps-widget, but they are all have definite number of screens. But I have potencially indefinite number of screens.
Also I tried to use only 3 fixed screens and to change their contents while sliding, but this leads to blinking, because after sliding is finished, I change the adapter for gridview and it refreshes contents. For example, I slide to the right and change left screen's gridview adapter from "yesterday" to "today", central screen's gridview adapter from "today" to "tomorrow" and right screen's gridview adapter from "tomorrow" to "day after tomorrow". This approach works fine, but refreshing contents after chaging adapter is not good!
Any ideas about how to adapt one of this pagers to indefinite number of screens?
You could try using a Gallery and setting each view of the gallery to match_parent
Have a look here: Endless Pager. It extends the PagerAdapter class and implements the OnPageChangeListener interface and can be used with the ViewPager widget (all this components are in the support library). It creates a loading element every time the page end is reached or a footer element if there are no more pages.
Related
I need to show one thousands question with 4 options to fill using one activity. I got an idea to use viewpager, but cant able to show 1000 fragment.
It is possible to use ViewPager with 1000 fragments. Just make sure that your adapter extends FragmentStatePagerAdapter.
From the documentation:
This version of the pager is more useful when there are a large number
of pages, working more like a list view. When pages are not visible to
the user, their entire fragment may be destroyed, only keeping the
saved state of that fragment. This allows the pager to hold on to much
less memory associated with each visited page as compared to
FragmentPagerAdapter at the cost of potentially more overhead when
switching between pages.
In my project I have an Activity that loads a list of news. When the list is loaded, this Activity is populated with the information of the first item on the list:
But since this loads all the news from the server, I want the user to be able to swap the news with his finger. For example: we start with news[0] and user swipe left, the content change to news[1]. The user swipe left again and the content changes to news[2] and so on... if the user swipes right, then it return to the previous news (news[1]). The header should not have a swipe movement, only the main frame (image and body should change):
What would be the best aproach for this behavior? I was thinking about using a TabLayout with ViewPager but I'm not sure if this is the correct way to do this. If I have something like 100 news this could be a overkill to load 100 fragments in the ViewPager right?
Does android have a better way to do this? How should I do this?
You can use ViewPager for that. Having 100 fragments inside is totally fine because ViewPager will only load as much as you set using setOffscreenPageLimit(pageLimit). For instance, if you set pageLimit = 3, ViewPager will only initialize 3 (up to 6) neighbour fragments that are on the right/left side of your currently visible fragment. And while you're swiping through fragments, it will kill the fragments that are out of this limit, and load new ones. So, there will be no overkill.
I have created RecyclerView with list of clients (from 0 till 14). I need maximum down state. For this purpose I am using method RecyclerView.scrollToPosition(14).
When RecyclerView are placing in Activity, I have the good result.
IMAGE: RecyclerView are placing in Activity
And now I am inflating new RecyclerView and put it in Dialog. The Adapter of RecyclerView the same. Method RecyclerView.scrollToPosition(14) give me the bad result (scroll is not set on the 14th position, by the way I can pull it to the down manually):
IMAGE: Bad result in Dialog
Why it happens? I think the problem in parent (Dialog) of RecyclerView. But I don't know what to do.
UPDATED! I think this is a really bug of RecyclerView. Because with ListView is all right (in my case with setSelection(14)).
Because your interaction panel hide the last element. Position your recycler view above the panel.
I've got a question regarding list views in Android. I want to create an activity that can display lots of information. I want to display each player horizontally (there could be anywhere from 2 to 256 players, but most likely there will be like 8) and there will be 10 - 20 rows under each player.
Is there a way to create a ListView that can scroll both directions? If not, what is the correct design approach to handle this type of problem?
I've tried to look into this a bit, and a GridView won't work because there will be items hanging off the screen; they won't all fit in the grid.
Thanks!
-Justin
Use a ViewPager instead so that the user can scroll through the player in the horizontal way that you want.
This way each player will be in a fragment, and the fragment can contain a vertical list that will show the rows that you require.
The benefit of this is that the viewpager can handle a huge number of players and rows for each player without impacting memory performance and in a less cramped space.
You can try using an ExpandableListView or a ViewPager.
I'm writing a glass app.
In one activity I want to scroll between few cards (which were popups in my android app).
1) I thought to use cardsScrollView.
problem: Is it possible to set customView to a card object?
2) I thought to use LiveCard
problems:
Is it possible to publish them inside my app and not in the timeline?
Is there an equivalent LiveCardsScrollView?
Any other idea how to implement this?
From Google's sample code at https://developers.google.com/glass/develop/gdk/ui/theme-widgets and API documentation at https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/widget/CardScrollView and https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/widget/CardScrollAdapter, it seems your 1) is possible, because:
1) The CardScrollAdapter's method public View getView(int position, View convertView, ViewGroup parent) returns a View (not a Card);
2) CardScrollView's get methods also return a View or Object, not Card specifically;
3) You can replace private List<Card> mCards; in the sample code (link #1 above) with private List<MyView> mViews;
But the documentation at those links also use Card as example, and the word cards seem to refer to static cards. So will have to test to find out for sure. However, there's a statement in link #1 that says "You can build a standard view hierarchy yourself or use the Card class.", suggesting it's possible to use a custom view.
I'll get back with you within 12 hours after I test with my Glass tonight.
As for your question 2, the answer is yes - you publish the scrollable content inside your app and not in the timeline. You can launch the activity (as in the sample code in Google's link #1) from a menu item selection, and the menu is attached to your livecard. Then inside that scrolling view, you can only swipe left and right to see other cards (or maybe custom views) in the scrolling view, but not the timeline. You have to swipe down to exit the activity (immersion) to go back to livecard, then you can swipe left and right and see the timeline. Note the scrolling view is not like static cards and will never show in the timeline. Also note that inside the scrolling view, you may use GestureDetector to capture other gestures (besides swipe left and right and down).
Just confirmed: custom views can be added to CardScrollView! I used a view that extends FrameLayout and inflates a layout xml file, and added three such views to CardScrollView. It works nicely!
Also tried to add a custom view that does the Canvas drawing, but haven't been able to see it shown in the scrolling view. Will try more later.
Just tested and found you can add any views to the CardScrollView - I'm able to add 4 custom views to a scrollview: one static Card, one view with Canvas drawing, one with OpenGL ES 1.0 drawing, and the final one with OpenGL ES 2.0 drawing. This is good to know to me! Thanks for your question.