How to create this view(at most 4 images in a page then swipe rest as same)? - android

Let's say I have dynamic number of items coming from server. I can only show 4 items at most in one page. Other pages whould be accesible with swipe Please have a look at the image below. What is the best way to achieve this?

This could be achieved using
View pager
Pager Indicator
A fragment with four view (Use proportionate layout) or use grid
view
Approach
The decision on number of pages will lie on the data received from
server.
For example:
if number of item recieved is 17
the number of pages will be 17/4+ 1(only if 17%4>0)
pass the page index to the fragment along with the complete list.
For example if page index in view pager 4
Make sure to keep the check ( index+4<=size of list of item)
if (index+4>size of list of item) then the the item to be displayed will start from index and will go on till the size of list.
if(index+4<=size of list)the item to be displayed will start from index i.e 4 in this case till next four element in list of items provided to the fragment.
In this way you can always get the required item out of the complete list

Related

ReclycleView with grouped data and responsive header for Landscape and Portrait mode

I am trying to achieve something like the picture, I have grouped data , and every group can have 1 or more (different count of items) , most items in the groups share the view type which is simple icon , title, description kind.
But the tricky part is how can I get the header (in landscape mode ) aligned to first item of the group , and allow it to scroll with the list.
One way I could think was let one item in the recycleView be the whole group . i.e header + list items , but that would not give the recycling of the views, defeating whole purpose of reclycleview.
I am looking for some pointers or ideas on how I could approach this.
Note : Header height could be larger that item height and may extend till second item in the group. basically imagine the header to be an Icon and text

Recyclerview with X items and View more button

I would like to know if there is any way how to implement RecyclerView with only part of the collection. For example, the ArrayList would have 10 bitmaps in it, but only 6 can fit the screen without scrolling. So I want to show only 5 of them, and the 6th would be a clickable Button/ImageView which would say 'View 5 more'.
Is it possible to achieve this? Thanks.
one way would be having 2 lists in your adapter, one is the list that you actually show (show list) and the other one the full dataset. as long as you're not showing the full dataset, add a row at the end with the button show more, when clicking the button add a new batch of items from the full dataset to the show list.

How to show listview items and limit them to have pages like?

I'm using Android Studio, and I have a listView that musts display an important amount of items. showing all of these items have a huge impact on performances. SO I would like to show them 10 by 10, and with a button show the 10 next items. After some researches, I found this android How to limit list items display in ListView and a button show more and this How to limit list items display in ListView by 10 and next 10after clicking next button. But these didn't lead me to a success. The 1st link looks easier but I didn't know where to put the code samples to make it work. Thanks for help !
You dont need to show "Load More" Button always. You can use Android's Recycler View for this. It will load only the data which can be shown on screen. Rest of the data will be loaded as you scroll down. And the view which is scrolled up (Vanishing views) are recycled automatically.
Check this links
https://developer.android.com/training/material/lists-cards.html
https://guides.codepath.com/android/using-the-recyclerview
https://www.binpress.com/tutorial/android-l-recyclerview-and-cardview-tutorial/156
First link question have a simple answer, If you made a custom adapter for populating listview then there will be a getCount() method which will return the number of items you want to show on listview. if you have not getCount() method then simply override it.
Link
there i(variable) have that value which number if items you want to show on listview, on refresh button click increment the value of i(variable) that will again refresh the whole listview and add the total number of items in listview which is the value of i(variable)

Android: How to dynamically replace a list view with another list view like Instagram with onClick?

I'm building an android app and I'm trying to replace a list view with another list view if you click a button, like the notifications page on Instagram. On that page, if you click on the top "following" button it will show you a listview of what your followers have liked. If you click on the "you" button it will show you a listview of what people have liked your photos.
Any help would be greatly appreciated!
You can do it by following ways,
1. add Two listviews and can change the visibility as per your requirement.
2. On button click you can load the other data into same list view and can update your adapter in the same list view.
in 1 you have to load two list view at first which will consume more time if data is larger sure you can write a login in asynctask to load list views in background thread.
in 2 you have to update your adapter at the button so you will have to provide some progress bar of dialog for user while you list view is getting update.
You can use either of this whichever suites you best.
Simply , You don't need to switch Listview , you only need to switch adapters .
eg, you can switch to mFollowingAdapter when clicked on Following button and switch to mYouAdapter when you select "You" tab. that's it.
You should write a list, that has a custom adapter. This adapter will be able to display BOTH views you want to display.
If the data to be displayed is the same format (ie. both have an imageview next to a textview), you are in good shape.
When you want to switch to a different list, get the information you would like to display, replace the data in your the collection backing your list, then notify the list that the data has changed, and it should redraw.
So, this might look like:
create ArrayList() with data A
setup List, with this data and display
replace the ArrayList() with data B
call listView.notifyDataSetChanged
You can still do this if the Data A, and Data B have different views, in this case, you would need to handle this logic in your custom adapter.

Headings under Navigation Drawer

How to add Headings in drawer layout. For example in YouTube application it has Headings in it's drawer like Subscription and from YouTube... So How we can add such Headings in Drawer Layout?
Check below image I want to add heading like "Subscription" used in this image.
The magic is happening in the Adapter that is feeding views to the ListView.
When a ListView is scrolled, it has to display whatever row is next in the data set. Instead of having to do this on their own, ListViews are backed by an Adapter. The ListView essentially asks the adapter for the next view (naming an index value) every time it needs to scroll up or down.
The Adapter can pass the ListView whatever it wants. When the ListView asks for row x (an index value), the Adapter can look at the data set and see that row x should be a special header. The adapter builds or recycles a special header view and passes it to the list view.
See the List View Guide for example code.

Categories

Resources