--------------------------MainActivity------------------
package com.loggedin.mmf.myapplicationpagination;
import android.content.Context;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
public final String TAG = "MainActivity";
ArrayList<Dessert> desserts = new ArrayList<>();
ContactListAdapter contactListAdapter;
RecyclerView recycler_view_list;
int lastScrollPosition = 0;
LinearLayoutManager linearLayoutManager;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
randomDataLoad();
recycler_view_list = findViewById(R.id.recycler_view_list);
linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setStackFromEnd(true);
recycler_view_list.setLayoutManager(linearLayoutManager);
contactListAdapter = new ContactListAdapter(context, desserts, new ContactListAdapter.OnItemClickListener() {
@Override
public void onItemCLick(View view, int position, List<Dessert> dessertsArrayList) {
if (view.getId() == R.id.tv_contact_name) {
/*
// dataget(position, dessertsArrayList);
*/
}
}
});
recycler_view_list.setAdapter(contactListAdapter);
recycler_view_list.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
lastScrollPosition = linearLayoutManager.findLastCompletelyVisibleItemPosition();
Log.v(TAG, "LastPosition: " + lastScrollPosition);
if (lastScrollPosition > 60) {
dataNew();
contactListAdapter.notifyDataSetChanged();
Toast.makeText(MainActivity.this, "DATA LOAD NEW", Toast.LENGTH_SHORT).show();
contactListAdapter = new ContactListAdapter(context, desserts, new ContactListAdapter.OnItemClickListener() {
@Override
public void onItemCLick(View view, int position, List<Dessert> dessertsArrayList) {
if (view.getId() == R.id.tv_contact_name) {
/*
// dataget(position, dessertsArrayList);
*/
}
}
});
}
}
});
}
private void dataNew() {
for (int i = 160; i < 280; i++) {
Dessert dessert = new Dessert();
dessert.setUsername(String.valueOf(i));
desserts.add(dessert);
}
}
private void randomDataLoad() {
for (int i = 0; i < 150; i++) {
Dessert dessert = new Dessert();
dessert.setUsername(String.valueOf(i));
desserts.add(dessert);
}
}
}
import android.content.Context;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
public final String TAG = "MainActivity";
ArrayList<Dessert> desserts = new ArrayList<>();
ContactListAdapter contactListAdapter;
RecyclerView recycler_view_list;
int lastScrollPosition = 0;
LinearLayoutManager linearLayoutManager;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
randomDataLoad();
recycler_view_list = findViewById(R.id.recycler_view_list);
linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setStackFromEnd(true);
recycler_view_list.setLayoutManager(linearLayoutManager);
contactListAdapter = new ContactListAdapter(context, desserts, new ContactListAdapter.OnItemClickListener() {
@Override
public void onItemCLick(View view, int position, List<Dessert> dessertsArrayList) {
if (view.getId() == R.id.tv_contact_name) {
/*
// dataget(position, dessertsArrayList);
*/
}
}
});
recycler_view_list.setAdapter(contactListAdapter);
recycler_view_list.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
lastScrollPosition = linearLayoutManager.findLastCompletelyVisibleItemPosition();
Log.v(TAG, "LastPosition: " + lastScrollPosition);
if (lastScrollPosition > 60) {
dataNew();
contactListAdapter.notifyDataSetChanged();
Toast.makeText(MainActivity.this, "DATA LOAD NEW", Toast.LENGTH_SHORT).show();
contactListAdapter = new ContactListAdapter(context, desserts, new ContactListAdapter.OnItemClickListener() {
@Override
public void onItemCLick(View view, int position, List<Dessert> dessertsArrayList) {
if (view.getId() == R.id.tv_contact_name) {
/*
// dataget(position, dessertsArrayList);
*/
}
}
});
}
}
});
}
private void dataNew() {
for (int i = 160; i < 280; i++) {
Dessert dessert = new Dessert();
dessert.setUsername(String.valueOf(i));
desserts.add(dessert);
}
}
private void randomDataLoad() {
for (int i = 0; i < 150; i++) {
Dessert dessert = new Dessert();
dessert.setUsername(String.valueOf(i));
desserts.add(dessert);
}
}
}
----------------recycler_view_list.xml----------------
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recycler_view_list"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
----------------ContactListAdapter----------
package com.loggedin.mmf.myapplicationpagination;
import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
public class ContactListAdapter extends RecyclerView.Adapter<ContactListAdapter.DessertVh> {
private ContactListAdapter.OnItemClickListener itemClickListener;
public static final String TAG = "NearContactAdapter";
private List<Dessert> dessertsArrayList;
private Context context;
public ContactListAdapter(Context context, List<Dessert> dessertsArrayList, ContactListAdapter.OnItemClickListener itemClickListener) {
this.context = context;
this.dessertsArrayList = dessertsArrayList;
}
@NonNull
@Override
public ContactListAdapter.DessertVh onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.contact_list_adapter, parent, false);
return new ContactListAdapter.DessertVh(view);
}
@Override
public void onBindViewHolder(@NonNull final ContactListAdapter.DessertVh holder, @SuppressLint("RecyclerView") final int position) {
final Dessert dessert = dessertsArrayList.get(holder.getAdapterPosition());
holder.tv_contact_name.setText(dessert.getUsername());
holder.tv_contact_name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
itemClickListener.onItemCLick(view, holder.getAdapterPosition(), dessertsArrayList);
}
});
//shirsh
}
@Override
public int getItemCount() {
return dessertsArrayList.size();
}
public static class DessertVh extends RecyclerView.ViewHolder {
TextView tv_contact_name;
public DessertVh(View itemView) {
super(itemView);
tv_contact_name = itemView.findViewById(R.id.tv_contact_name);
}
}
public interface OnItemClickListener {
void onItemCLick(View view, int position, List<Dessert> dessertsArrayList);
}
}
-------------Dessert-----------------------
package com.loggedin.mmf.myapplicationpagination;
public class Dessert {
public String getUsername() {
return Username;
}
public void setUsername(String username) {
Username = username;
}
public String getUsernumber() {
return Usernumber;
}
public void setUsernumber(String usernumber) {
Usernumber = usernumber;
}
String Username;
String Usernumber;
}
-----------contact_list_adapter.xml--------
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv_contact_name"/>
</android.support.constraint.ConstraintLayout>