Load Infinite View in Recycler View - android

I am using The Movie Database Api to load Tv Shows in my recyclerview. I am able to load the views in my recycler view. The url i am using is https://api.themoviedb.org/3/tv/airing_today?api_key=MY_API_KEY&page=1
It loads all the views from page 1 in my recyclerview. What i want is as soon as user reaches end of recyclerview it should load the next page and so on i.e at the end of recycler view i want to load https://api.themoviedb.org/3/tv/airing_today?api_key=MY_API_KEY&page=2
I know i can do it by adding next and previous button below my recyclerview,but i don't want to do that approach. How to automatically load next page as soon as user reaches end of recycler view. FYI,I am using Retrofit. Please help.

Related

How to refresh selected item In paging library

I am using the android paging library to show a list of posts in the recycler view, my data source loads data from inMemory list which I add and remove from it then invalidate the data source to refresh the PagedListAdapter, everything is working well, but the problem is that when I scroll through pages, for example, page #5, and delete some item and call invalidate(), the data source will be re-initialized and will invoke the callbacks again, which re-loads the items in the recycler view, and jump to the first page.
The question is: How to refresh the items without jumping to the first page, and stick in the selected position?
Thanks.

Start Recyclerview from a particular cursor position

I have a RecyclerView which is linked to a CursorLoader.
So my question is how to start from a particular position is database when loading the RecyclerView.
I don't want to use scrollToPosition because i don't want those items be loaded in the view initially.
In other words i want to start the recycler view from the middle of the data set or from a particular row.
Thanks
Solved.
Used scrollToPositionWithOffset after finishing the loading.

android listview select from top with problems

I add header view to listview ,and there is a webview in header to show local html content,and listview shows comments.
I user selectFromTop after adapter has finished load data in order to show first comment item,but some times it doesn't work,what's wrong??

Load list items on demand

I would like to load a list of messages on demand.
I show 20 messages on my listview and when the user scrolls on top of list there is a button to load more 20 messages.
Like whatsapp, when user clicks on the button, more messages are loaded above and the user can scroll 20 more messages.
I have tried to make it with Loaders, every time the button is clicked I publish an event that load messages on the adapter.
However when the adapter is releoaded with new itens the focus goes to end of list.
I have tried to set the focus to the right positon, but the Loader's events reload the adapter and the focus come back to end of list.
The only solution I found was to set the focus after a time, but the user can see the list going to end and coming back to the right postion.
How can I load messages on demand like Whats app?
You have to add only 20 objects in your ArrayList and add HeaderView in your list adapter .On click on headerView .It will load more 20 items in your list adapter . and call notifyDataSetChange(); afterwards.

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.

Categories

Resources