0

I am new in firebase android app development. In this app i fetched the data from firebase database. Here i want to implement show more functionality in recyclerview to save data loading. I see the solution in many stackoverflow question. But in every question The adapter class is defined outside from main activity. so i cant understand properly. And here my adapter is within main activty class.

class MainActivity extends AppCompatActivity {


    private RecyclerView postList;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PostRef=FirebaseDatabase.getInstance().getReference().child("Posts");
        postList = (RecyclerView) findViewById(R.id.all_user_post_list);
        postList.setHasFixedSize(true);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setReverseLayout(true);
        linearLayoutManager.setStackFromEnd(true);
        postList.setLayoutManager(linearLayoutManager);
        displayAllUserPost();
    }

    private void displayAllUserPost() {

        Query sortPost=PostRef;
        FirebaseRecyclerOptions<Post> options=new FirebaseRecyclerOptions.Builder<Post>().setQuery(sortPost,Post.class).build();
        FirebaseRecyclerAdapter<Post, PostsViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<Post, PostsViewHolder>(options)
            @Override
            protected void onBindViewHolder(@NonNull final PostsViewHolder holder, final int position, @NonNull final Post model) {

                final String PostKey = getRef(position).getKey();
                holder.postfullname.setText(model.getFirstname() + " " + model.getLastname());
            }


        @NonNull
        @Override
        public PostsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
        {
            View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.all_post_layout,parent,false);
            PostsViewHolder viewHolder=new PostsViewHolder(view);
            return viewHolder;
        }
        }
    }
    public static class PostsViewHolder extends RecyclerView.ViewHolder
    {

        TextView postfullname;

        public PostsViewHolder(View itemView)
        {
            super(itemView);
            postfullname = itemView.findViewById(R.id.user_post_full_name);
        }
    }
}

So How i add show more functionality in this code when first load only 10 items and than after load more 10 items with rounded progressbar(show more button is not important).

Most important thing is that first load only 10 items. rest item should not be loaded until user scrolled down to last(10th) item

Thank you.

tailor
  • 373
  • 4
  • 19
  • Try this https://stackoverflow.com/questions/37711220/firebase-android-pagination – Mini Chip Jun 12 '19 at 14:38
  • https://stackoverflow.com/questions/37711220/firebase-android-pagination ,,In this they used childListener, Arraylist,EventListner and here i used onbindviewholder so cant understand properly .thanx – tailor Jun 12 '19 at 14:58

0 Answers0