I'm learning how to build an adapter like the one demonstrated in Currents.
I know the basic classes used to achieve what we see in currents : ViewPager, ViewPagerIndicator, and a custom view showing 6 ImageViews and textviews below it.
My question is, how do we go about building a custom adapter that will automatically fill in 6 items in the first viewpager page, and continue filling it on the next page automatically? I'm guessing it will be something along the idea where the number returned from getCount() will be used to determine how many viewpager "pages" are there, (in this case divide by 6 ).
I have successfully tried building a similar view using GridView + viewpager+indicator, but i'm sure Currents is not using gridview to achieve this. Since this is definitely not extending ListView nor GridView, how can i go about solving this? Thanks in advance.
Related
I am trying to implement Instagram like Search fragment where they have explore posts(contains only the image) in a grid layout and when we click on them, it changes to another feed like view showing more details.
The way I am thinking to implement is to have two fragments with recycler views: 1 for grid layout and 1 for feed like. Share the currently, loaded feed items between these two recycler view adapters.
Question: Is it the correct approach to share adapter items between two views? If not, what would the design be? I suspect I will run into issues if we share the items.
Kindly let me know if any more details is needed. I can share pictures as well in case someone needs for android device.
I went ahead and implemented my design. Till now, I haven't seen any issues.
I want to have a bunch of images that show how my app works and have a dot-type pager at the bottom, like the example below. What UI Element should I be using?
Is Android ViewPager suitable for this? how will be adding the small circles below which act like page numbers.
EDIT: After I posted this question, I found this library. Would like feedback on how to do this from scratch.
Actually, if you look thought the code at https://github.com/JakeWharton/ViewPagerIndicator you can get a nice feedback on how to do it from scratch. The lib uses a custom View , but you can emulate this kind of behavior with some existent views, for instance. Basically:
Create a LinearLayout below your ViewPager. Set the orientation to horizontal;
Put some RadioButtons in it (you can do it dynamically based on your adapter size);
In your Activity, Fragment or whatever set a PagerListener for your ViewPager;
This listener is provided by the ViewPager API and you can check and uncheck your RadioButtons according to the position in the ViewPager with the method onPageSelected(int position), for instance.
There you go, a (very) basic ViewPagerIndicator.
I need to implement an application which uses a sliding view (ViewFlipper) for one of its activity, this activity displays information stored on and array and passed from the previous activity via intent. The number of slides or tabs is expected to vary depending on the number of elements in the array. i.e for 4 elements in the array,we shall get 4 slides and when there is only 3, we have the same amount of slides displaying respective information accordingly.
Any idea on how to implement this, an example if possible? I am very new to android development. please help
Create an .xml file now implement a view flipper design the layout of how each pages work. I suggest using a relative layout and add those views inside the view flipper. Seems pretty basic now go search tuts on .xml, viewflippers, types of layout, textviews, and don't put questions here next time asking for answers. We are a community after all helping people with problems who actually tries to do something not for copy and paste people.
For this purpose it's best not to use the ViewFlipper, but instead use a ViewPager to which you can dynamically add 'subviews' (pages) using a PagerAdapter. ViewPager will provide performance benefits over ViewFlipper as it loads (and removes) pages on-demand (like a ListView).
Set-up of the ViewPager is in essence the same as setting up a ListView. You can use the ViewPager on Android <3.0 devices using the compatibility library.
Create your own class that extends PagerAdapter, and set mViewPager.setAdapter(mAdapter);. In your adapter, in the method instantiateItem() you will build your 'page' and add it to the parent with mViewPager.addView(newView);.
For a more detailed example of how to set-up a ViewPager see my answer here.
I want to create a horizontal listview which contain many item, one item will contain a image. When user slide listview => the count of item will be fix when it display, example display only 3 or 4 image. How can I do that? Many thanks.
Edit:
I use this
to create a HorizontalList view, everything is ok but I don;t know how to make the Next and Previous button work! Any idea?
Instead of a horizontal ListView (which, as far as I know, isn't offered by the Android SDK) you can use a HorizontalScrollView. You can add the items like to any other kind of layout class.
It looks like what you are looking for is a Paginated Gallery. I have written one here.
Its still only a couple of days old but hopefully the included Activity code will get you off the ground.
hi i want to split my gallery with 5 images in 2 rows.
Please let me know how to do this in android using Gallery View & custom adapter for Gallery view.
Is there any sample code available please share it, i have already checked the previous posts in this site.
Thanks
If you still need this and Pagination instead of scroll will work for you, you might look at: https://github.com/sfarooq/PaginatedGallery
I designed it using ViewPager so you can manipulate the adapter to send any kind of views you want including two row views.
If you must use scrolling galleries you could implement two separate gallery in a vertical orientation and send touch events from each to the other.