what you are asking is basically an endless scrolling recyclerview with a loaderview at the bottom that accepts click to load additional data.
You have to make use of multiple viewType
in the RecyclerView.Adapter
I encourage you to search more before asking a new question as there are countless tutorials for this and similar questions on stackOverflow. Here's a link to an example on stack on how to implement multiple viewTypes.
I'll share some points on one of the ways to achieve what you are looking for.
First in your adapter you need to declare two constants
private final int VIEW_ITEM = 0;
private final int VIEW_LOADER = 1;
and a boolean showLoadMore
create a public method
public void showLoader(boolean status) {
this.showLoadMore = status;
}
this can be used to show/hide loader from your activity
You need to override getItemCount()
method to return the correct number of rows as it keeps changing base on your loader
@Override
public int getItemCount() {
if (yourList.isEmpty()) {
return 0;
} else {
if (showLoadMore)
return yourList.size() + 1;
else
return yourList.size();
}
}
Override getItemViewType(int position)
, since your loader needs to be at the bottom , it should
return (position == yourList.size() && showLoadMore) ? VIEW_LOAD : VIEW_ITEM;
Next as shown in the link i shared above, you need to inflate your layout in onCreateViewHolder
method and then bind your layout in onBindViewHolder
method based on your viewTypes. you can simply use if else condition as this case only has 2 viewtypes.
Now in your activity after you setAdapter on the recyclerview and have fetched the n data set adapter.showLoader(true) to show the loader view and notifyDataSetChanged()
. You can customize the loaderview to show progress bar or however you like , on click fetch the next set of data, if new count is less than required count count <= n
then make set adapter's showLoader(false)
and adapter.notifyDataSetChanged()
this will hide your loader view after adding the data.
Hope this answer helps you in some way,
Meanwhile here's a tutorial from web implementing endless scrolling recyclerview in another way