Custom Adapter RecyclerView

Additional

Language
Java
Version
1.0.4 (Jul 5, 2019)
Created
Jan 2, 2019
Updated
Jul 5, 2019
Owner
Farshid Roohi (FarshidRoohi)
Contributor
Farshid Roohi (FarshidRoohi)
1
Activity
Badge
Generate
Download
Source code
APK file

Commercial

Custom Adapter RecyclerView

Very simple use android recyclerView adapter and endlessScrolled in android support library recyclerView

  • Clean uses
  • Ability add custom layout in progress pagination and default layout
  • Support linear, Grid, StaggeredGrid LayoutManger for endless and show layout progressView
screenShot:

gradle :
  implementation 'androidx.recyclerview:recyclerview:1.0.0'
  implementation 'ir.farshid_roohi:customAdapterRecycleView:1.0.4'
  • Your project should support

    DataBinding

for more information It

Example

Sample Adapter

public class MyAdapter extends AdapterRecyclerView<String> {

    @Override
    public int getItemLayout(int viewType) {
        return R.layout.my_item;
    }

    // optional method override layout progress custom
    @Override
    public int onProgressLayout() {
        return R.layout.my_custom_progress_item;
    }

    @Override
    public void onBindView(ViewDataBinding viewDataBinding, int position, int viewType, String element) {
        MyItemBinding itemBinding = (MyItemBinding) viewDataBinding;
        itemBinding.txtTitle.setText(element);
    }
}
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        
        final MyAdapter adapter = new MyAdapter();
        adapter.endLessScrolled(recyclerView);
        adapter.addItems(getTempItems());
        recyclerView.setAdapter(adapter);


        // handled click item in recyclerView
        adapter.setOnClickItemListener(recyclerView, new OnClickItemListener<String>() {
            @Override
            public void onClickItem(int position, String element) {
                Toast.makeText(getApplicationContext(), "item click : " + element, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onLongClickItem(int position, String element) {
                Toast.makeText(getApplicationContext(), "item long click : " + element, Toast.LENGTH_SHORT).show();

            }
        });


        // handled endless recyclerView
        adapter.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore() {
                adapter.showLoading();

                // request or load other items...
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        adapter.addItems(getTempItems());
                    }
                }, 2500);
            }
        });
        
        
        
 // get temp list item
    public List<String> getTempItems() {
        List<String> items = new ArrayList<>();

        for (int i = 0; i <= 15; i++) {
            items.add("item ");
        }

        return items;
    }