Skip to content

A lightweight simple and practical RecycleViewAdapter auxiliary class library

Notifications You must be signed in to change notification settings

HotBitmapGG/EasyRecyclerAdapterHelper

Repository files navigation

EasyRecycleAdapterHelper

一个简单实用的RecycleViewAdapter帮助库

简介

  • 1.RecycleView的OnItemClick,OnItemLongClick的点击事件
  • 2.RecycleView的Item动画,默认实现了一种动画效果,可自行扩展
  • 3.添加头部尾部,分割线
  • 4.列表和表格布局的上拉加载更多

截图

使用说明

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

   allprojects {
   	repositories {
   		...
   		maven { url "https://jitpack.io" }
   	}
   }

Step 2. Add the dependency

   dependencies {
           compile 'com.github.HotBitmapGG:EasyRecycleAdapterHelper:V1.1'
   }

Demo

  * Adapter

   @Override
   public ClickableViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
   {

       //绑定上下文
       bindContext(parent.getContext());
       //创建ViewHolder
       return new ItemViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.item_main, parent, false));
   }

   @Override
   public void onBindViewHolder(ClickableViewHolder holder, int position)
   {

       if (holder instanceof ItemViewHolder)
       {
           ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
           itemViewHolder.mTextView.setText(datas.get(position));

           //添加动画
           showItemAnim(itemViewHolder.mLayout, position);
       }
       super.onBindViewHolder(holder, position);
   }

   * Activity

             //初始化RecycleView
             mRecyclerView = (RecyclerView) findViewById(R.id.recycle_view);
             assert mRecyclerView != null;
             mRecyclerView.setHasFixedSize(true);

             //设置LayoutManager
             LinearLayoutManager mLinearLayoutManager = new LinearLayoutManager(this);
             mRecyclerView.setLayoutManager(mLinearLayoutManager);

             //设置分割线
             //mRecyclerView.addItemDecoration(new EasyDividerItemDecoration(this ,EasyDividerItemDecoration.VERTICAL_LIST));

             //创建Adapter
             mRecycleAdapter = new RecycleAdapter(mRecyclerView, datas);

             //使用EasyAdapter包装一层 添加头部 尾部
             EasyRecycleAdapter mEasyRecycleAdapter = new EasyRecycleAdapter(mRecycleAdapter);

             //添加头部
             createHead();
             mEasyRecycleAdapter.addHeaderView(headView);

             //添加尾部 上拉加载更多
             createFoot();
             mEasyRecycleAdapter.addFooterView(footView);

             //设置适配器
             mRecyclerView.setAdapter(mEasyRecycleAdapter);

             //添加Scroll监听 上拉加载更多数据
             mRecyclerView.addOnScrollListener(new EasyRecycleOnScrollListener(mLinearLayoutManager)
             {

                 @Override
                 public void onLoadMore(int currentPage)
                 {
                     //这里是上拉更多数据的逻辑
                     page++;
                     loadMoreData();
                 }
             });

             //设置item点击事件
             mRecycleAdapter.setOnItemClickListener(new EasyBaseRecycleViewAdapter.OnItemClickListener()
             {

                 @Override
                 public void onItemClick(int position, EasyBaseRecycleViewAdapter.ClickableViewHolder holder)
                 {

                     Toast.makeText(MainActivity.this, datas.get(position), Toast.LENGTH_SHORT).show();
                 }
             });
   

Other

License

Copyright 2016 HotBitmapGG

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

A lightweight simple and practical RecycleViewAdapter auxiliary class library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages