Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Adapter 一些建议

Open
#88 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
android, java
Domain
mobile

Research direction

Start by reading the LoadMoreAdapter, MultiItemTypeAdapter, and ItemViewDelegate APIs, focusing on the listed methods and constructor behavior. Separate the four proposed changes into independently scoped decisions; done means the maintainers have agreed on a concrete scope and the affected behavior is covered by the repository's existing checks.

Written by the indexing model from the issue text.

Description

你好,看了你的代码,觉得很不错。在使用这个库的时候有几个想法:

关于LoadMoreAdapter

  1. 关于设置:hasLoadMore 这个方法是private。为什么不能设置 getter setter?很多时候加载更多的时候,如果没有更多的时候,能简单的设置hasLoadMore 不是更好吗?

  2. 错误处理,如果我在加载loadMore的时候,如果出现错误,如何显示一个错误的item?点击重新刷新?

关于 MultiItemTypeAdapter 数据安全 :

  1. 你的adapter 的 构造函数里面要求传入 List, 你将传入的赋予mData。 其实我觉得最好是你自己内部建立一个空的List, 避免null指针
public class MultiItemTypeAdapter<T> extends RecyclerView.Adapter<ViewHolder> {
    protected Context mContext;
    protected List<T> mDatas = new ArrayList<>();

    protected ItemViewDelegateManager mItemViewDelegateManager = new ItemViewDelegateManager();
    protected OnItemClickListener mOnItemClickListener;


    public MultiItemTypeAdapter(Context context) {
        mContext = context;
    }

    public void addData(List<T> datas) {
        mDatas.addAll(datas);
    }

    public void setData(List<T> datas) {
        mDatas.clear();
        mDatas.addAll(datas);
    }

关于 ItemViewDelegate

RecycleViewAdapter 有两个基本方法:
onCreateViewHolder
onBindViewHolder

个人觉得可以把 ItemViewDelegate#convert(ViewHolder holder, T t, int position); 分为两个方法 :

void create(View view); 这个方法用来初始化ViewHolder里面的Views (现在很多人喜欢用 butterKnife)这个方法在 onCreateViewHolder 调用

void convert(T t, int position); 这个方法在 onBindViewHolder 调用
因为在create()里面已经初始化了所有views 所以就不需要 ViewHolder holder 来调用 譬如
holder.setText() 这样的方法

Dominant language
Java
Stars
4.7k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from hongyangAndroid/baseAdapter

All issues in hongyangAndroid/baseAdapter

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.