项目作者: Qamar4P

项目描述 :
Simple adapter for RecyclerView
高级语言: Java
项目地址: git://github.com/Qamar4P/LolAdapter.git
创建时间: 2018-02-27T09:17:42Z
项目社区:https://github.com/Qamar4P/LolAdapter

开源协议:

下载


LolAdapterExample

Demo project to showcase my stupid simple LolAdapter for recycler view also avail in Kotlin, check out branch

This library use Java8 Lambdas and depends ButterKnife optional

How to use LolAdapter

XML
  1. <android.support.v7.widget.RecyclerView
  2. android:id="@+id/recyclerView"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:clipToPadding="false"
  6. android:paddingTop="@dimen/standard_wall_space"
  7. android:paddingBottom="@dimen/standard_wall_space"
  8. android:paddingEnd="@dimen/standard_wall_space"
  9. android:paddingStart="@dimen/standard_wall_space"
  10. app:layoutManager="LinearLayoutManager"
  11. tools:listitem="@layout/list_item" ></android.support.v7.widget.RecyclerView>

Simple List Adapter

Code
  1. ...
  2. LolAdapter<ItemModel,ItemViewHold> adapter = new LolAdapter<>(itemViewClickListener(),ItemViewHold::new);
  3. adapter.items.addAll(data);
  4. recyclerView.setAdapter(typeAdapter);
  5. ...
  6. class ItemViewHold extends LolViewHold<ItemModel> {
  7. @BindView(R.id.textTitle)
  8. TextView textTitle;
  9. @BindView(R.id.textDesc)
  10. TextView textDesc;
  11. ItemViewHold(ViewGroup parent) {
  12. super(parent,R.layout.list_item);
  13. }
  14. @Override
  15. public void bind() {
  16. textTitle.setText(data.fullName+" "+getAdapterPosition());
  17. textDesc.setText(data.location);
  18. }
  19. }

That’s it

Type List Adapter

Code
  1. ...
  2. LolAdapter<ItemModel, LolViewHold<ItemModel>>
  3. typeAdapter = new LolTypeAdapter<>(itemViewClickListener()
  4. ,position -> position == 0 || position == 4 ? 0 : 1,
  5. HeaderViewHold::new,
  6. ItemViewHold::new);
  7. adapter.items.addAll(data);
  8. recyclerView.setAdapter(typeAdapter);
  9. ...
  10. class HeaderViewHold extends LolViewHold<ItemModel> {
  11. @BindView(R.id.textTitle)
  12. TextView textTitle;
  13. HeaderViewHold(ViewGroup parent) {
  14. super(parent,R.layout.list_item2);
  15. }
  16. @Override
  17. public void bind() {
  18. textTitle.setText(data.fullName+" "+getAdapterPosition());
  19. }
  20. }

That’s it

Scrennshot