top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Adapter class in Java ?

+1 vote
2,454 views
What is Adapter class in Java ?
posted Mar 18, 2014 by Ashwini Miraj

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

An Adapter class provides the default implementation of all methods in an event listener interface. Adapter classes are very useful when you want to process only few of the events that are handled by a particular event listener interface. You can define a new class by extending one of the adapter classes and implement only those events relevant to you.

answer Mar 18, 2014 by Pavan P Naik
Similar Questions
0 votes

I have applied the pagination as per the below code but the new data is not added to the Recyclerview. it loading previous data again and again. In this, I have applied the filter in the recycler view to filter the list according to the category. But I am unable to apply the pagination to the filterable recyclerview. Please assist.

I am using Firestore database in Android Application. If any more information is required, Please let me know

CODE

public void onFilter(Filters filters) {
        // Construct query basic query
        Query query = mFirestore.collection("posts").orderBy("timestamp", Query.Direction.DESCENDING);

        // Category (equality filter)
        if (filters.hasCategory()) {
            query = query.whereEqualTo("postcategory", filters.getCategory());
        }


        // Limit items
        query = query.limit(5);


        Query finalQuery = query;
        finalQuery.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (DocumentSnapshot document : task.getResult()) {
                        PostsModel productModel = document.toObject(PostsModel.class);

                        mQuery = finalQuery;

                        adapter.setQuery(mQuery);
                       // list.add(productModel);
                    }

                    adapter.notifyDataSetChanged();
                    lastVisible = task.getResult().getDocuments().get(task.getResult().size() - 1);

                    RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
                        @Override
                        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                            super.onScrollStateChanged(recyclerView, newState);
                            if (newState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
                                isScrolling = true;
                            }
                        }

                        @Override
                        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                            super.onScrolled(recyclerView, dx, dy);

                            LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) recyclerView.getLayoutManager());
                            int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
                            int visibleItemCount = linearLayoutManager.getChildCount();
                            int totalItemCount = linearLayoutManager.getItemCount();

                            if (isScrolling && (firstVisibleItemPosition + visibleItemCount == totalItemCount) && !isLastItemReached) {
                                isScrolling = false;
                                Query nextQuery = PostsRef.orderBy("timestamp", Query.Direction.DESCENDING).startAfter(lastVisible).limit(5);
                                nextQuery.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                                    @Override
                                    public void onComplete(@NonNull Task<QuerySnapshot> t) {
                                        if (t.isSuccessful()) {
                                            for (DocumentSnapshot d : t.getResult()) {
                                                PostsModel productModel = d.toObject(PostsModel.class);

                                                mQuery = finalQuery;

                                                adapter.setQuery(mQuery);
                                               // list.add(productModel);
                                            }
                                            adapter.notifyDataSetChanged();
                                            lastVisible = t.getResult().getDocuments().get(t.getResult().size() - 1);

                                            if (t.getResult().size() < 5) {
                                                isLastItemReached = true;
                                            }
                                        }
                                    }
                                });
                            }
                        }
                    };

                    recyclerView.addOnScrollListener(onScrollListener);
                }
            }
        });


        // Update the query


        // Set header
        mCurrentSearchView.setText(Html.fromHtml(filters.getSearchDescription(getActivity().getApplicationContext())));

        // Save filters
        mViewModel.setFilters(filters);
    }
...