• Stars
    star
    168
  • Rank 225,507 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android 轻量级适配器,简化使用,适应所有的AbsListView、RecyclerView。支持HeaderView与FooterView~

EasyAdapter

Android万能适配器,通吃所有的AbsListView、RecyclerView。

添加依赖

buildscript {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
    dependencies {
        ...
    }
}
dependencies {
    implementation 'com.github.smuyyh:EasyAdapter:1.3.0'
}

用法

step1

// ListView
public class ListViewAdapter extends EasyLVAdapter<Bean> {

    public ListViewAdapter(Context context, List<Bean> list, int... layoutIds) {
        super(context, list, layoutIds);
    }

    @Override
    public void convert(EasyLVHolder holder, int position, final Bean bean) {
        holder.setText(R.id.tv, bean.name)
              .setText(R.id.tv2, bean.name2)
              .setImageResource(R.id.img, context.getResource().getDrawable(bean.imgRes));
    }

    @Override
    public int getLayoutIndex(int position, Bean item) {
        // 若需多样式布局,则重写该方法
        if (position % 2 == 0)
            return 1;
        else return 0;
    }
}

// RecyclerView
public class RecyclerViewAdapter extends EasyRVAdapter<Bean> {
    public RecyclerViewAdapter(Context context, List<Bean> list, int... layoutIds) {
        super(context, list, layoutIds);
    }

    @Override
    protected void onBindData(EasyRVHolder viewHolder, final int position, Bean item) {
        viewHolder.setText(R.id.tv, item.name);
        // 自定义点击可覆盖父类的setOnItemClickListener
        /*viewHolder.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext, position+"---", Toast.LENGTH_SHORT).show();
            }
        });*/
        viewHolder.setImageUrl(R.id.iv, "https://img.25pp.com//ppnews/zixun_img/6fc/096/1444271700253231.jpg");
    }

    @Override
    public int getLayoutIndex(int position, Bean item) {
        if (position % 2 == 0)
            return 0;
        else return 1;
    }
}

step2

// 1、若需要调用adapter.setImageUrl,可以在Application配置全局统一回调
AdapterImageLoader.init(new AdapterImageLoader.ImageLoader() {
    @Override
    public void loadImage(Context context, String url, ImageView view) {
        Glide.with(context)
                .load(url)
                .into(view);
    }
});

// 2、若adapter需要单独定制ImageLoader,比如placeHolder,则重写该方法,以替换全局初始化的ImageLoader
@Override
public AdapterImageLoader.ImageLoader getImageLoader() {
    return new AdapterImageLoader.ImageLoader() {
        @Override
        public void loadImage(Context context, String url, ImageView view) {
            Glide.with(context)
                    .load(url)
                    .override(10, 10)
                    .into(view);
        }
    };
}

step3

ListView lv = (ListView) findViewById(R.id.lv);
lv.setAdapter(new ListViewAdapter(this, list, R.layout.item_list_view_1, R.layout.item_list_view_2));

数据操作

EasyXXAdapter提供以下方法,便于对List数据的增删改。

    boolean addAll(List<T> list);

    boolean addAll(int position, List<T> list);

    void add(T data);

    void add(int position, T data);

    void clear();

    boolean contains(T data);

    T getData(int index);

    void modify(T oldData, T newData);

    void modify(int index, T newData);

    boolean remove(T data);

    void remove(int index);

    // RV 独有 点击事件
    void setOnItemClickListener(OnItemClickListener<T> itemClickListener);

    // RV 独有 长按事件
    void setOnItemLongClickListener(OnItemLongClickListener<T> itemLongClickListener);

More Repositories

1

BookReader

📕 "任阅" 网络小说阅读器,3D翻页效果、txt/pdf/epub书籍阅读、Wifi传书~
Java
6,562
star
2

ImageSelector

🌁 Android 图片选择器。充分自由定制,极大程度简化使用,支持图库多选/图片预览/单选/照片裁剪/拍照/自定义图片加载方式/自定义色调/沉浸式状态栏
Java
1,599
star
3

SprintNBA

🏀 NBA客户端
Java
632
star
4

CrawlerForReader

Android 本地网络小说爬虫,基于jsoup及xpath
Java
390
star
5

BubblePopupWindow

Android 实现各个方向的气泡弹窗,可控制气泡尖角偏移量。
Java
345
star
6

BankCardFormat

💳 自动格式化银行卡号的EditText,卡号格式化、归属银行及卡别判断
Java
282
star
7

EasyGuideView

Android app新手引导,任意View高亮提示,简单易用
Java
197
star
8

JsonViewer

Android json viewer, to convert json strings to a friendly readable format, it supports expend&collapsed json objects.
Java
195
star
9

IncrementallyUpdate

Android 应用增量更新
C
179
star
10

CommonLibary

CommonLibrary主要是自己整理的一些项目开发中常用的工具类、通用UI的集合,尽可能的覆盖Android开发中通用的一些东西
Java
139
star
11

AutoInstall

Android 无需Root实现APK的静默安装
Java
135
star
12

NestedRecyclerView

RecyclerView 嵌套 多Tab 吸顶容器,类似 盒马、朴朴超市 首页。
Java
111
star
13

StickyHeaderListView

仿滴滴打车开具发票页,ListView粘性Header
Java
89
star
14

HardwareTest

Android 各个硬件模块自动化测试。包括LCD、摄像头、键盘、闪光灯、声音、磁盘存储、震动、触摸屏、NFC及各类传感器的测试。
Java
87
star
15

StickyHeaderRecyclerView

RecyclerView 悬浮吸顶 Header,支持阴影、点击事件与状态绑定
Java
75
star
16

easyDAO

easyDAO is a light-weight&fast ORM library for Android that maps objects to SQLite , it becomes much easier to operate the SQLite database.
Java
35
star
17

ReactNativeTools

IntelliJ plugin, to make it easier to execute react-native commands
Java
26
star
18

GitHubWidgets

GitHub html widget, include User Widget、Repo Widget and Activity Widget.
JavaScript
18
star
19

SimpleMail

一个基于POP3和SMTP协议的邮件收发库
Java
10
star
20

ReflectionDemo

从Java反射机制到Android自定义注解框架
Java
10
star
21

AndroidLayoutIDConverter

Android Studio插件。快速生成findViewById代码/ButtefKnife注解/AndroidAnnotations注解~
Java
4
star
22

JustTest

contributions
Java
2
star