Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Baseadapter | 4,646 | 2 years ago | 112 | apache-2.0 | Java | |||||
Android 万能的Adapter for ListView,RecyclerView,GridView等,支持多种Item类型的情况。 | ||||||||||
Flipviewpager.draco | 1,845 | 4 years ago | 6 | Java | ||||||
This project aims to provide a working page flip implementation for usage in ListView. | ||||||||||
Asymmetricgridview | 1,724 | 36 | 5 years ago | 3 | July 01, 2015 | 33 | mit | Java | ||
Android ListView that mimics a GridView with asymmetric items. Supports items with row span and column span | ||||||||||
Renderers | 1,212 | 88 | 7 | 2 years ago | 22 | May 20, 2020 | 2 | apache-2.0 | Java | |
Renderers is an Android library created to avoid all the boilerplate needed to use a RecyclerView/ListView with adapters. | ||||||||||
Multichoiceadapter | 865 | 5 | 2 | 9 years ago | 11 | February 25, 2014 | 11 | apache-2.0 | Java | |
Android - A ListView adapter with support for multiple choice modal selection | ||||||||||
Pinnedheaderlistview | 676 | 8 years ago | 25 | Java | ||||||
A ListView with pinned section headers for Android | ||||||||||
Superadapter | 636 | 6 years ago | Java | |||||||
[Deprecated]. 🚀 Adapter(BaseAdapter, RecyclerView.Adapter) wrapper for Android. 一个Adapter同时适用RecyclerView、ListView、GridView等。 | ||||||||||
Android Arsenal.com | 532 | 3 years ago | 2 | HTML | ||||||
Source to android-arsenal.herokuapp.com | ||||||||||
Android_5.0_viewdemo | 481 | 4 years ago | 5 | Java | ||||||
一些基于 Android 5.0/6.0/N 新特性的小案例 | ||||||||||
Verticalbannerview | 436 | 7 years ago | Java | |||||||
a vertical banner view in android.you can find it in 淘宝app、京东app... |
Due to the growing use of the RecyclerView and the RecyclerView.Adapter provided adapter class, Easy-Adapter is now deprecated. Whilst the current version still remains usable, there will no longer be any new development taking place.
Using ListView
and RecyclerView
has never been so easy. Inspired by the view holder design pattern, this library provides an easier way of linking ListView
and RecyclerView
with the underlying data for that view without having to implement your own Adapter. EasyAdapter will do the tedious work for you.
ItemViewHolder
and use annotations to link your code to views and layouts. See examples below or demo app.ListView
and RecyclerView
. Once you implement your ItemViewHolder
this can be used with both widgets. By just changing a couple of lines you can easily switch between a ListView
and a RecyclerView
.EasyAdapter supports Android 2.1 and above.
dependencies {
compile 'uk.co.ribot:easyadapter:[email protected]'
}
<dependency>
<groupId>uk.co.ribot</groupId>
<artifactId>easyadapter</artifactId>
<version>1.5.0</version>
<type>aar</type>
</dependency>
Download the latest Jar
This example shows how to implement a ListView
and a RecyclerView
that displays a list of people. Every item on the list is a person with an image, name and phone number. The item's layout is person_item_layout.xml
and it contains an ImageView
and two TextViews
. The Person
class contains data about a person.
//Annotate the class with the layout ID of the item.
@LayoutId(R.layout.person_item_layout)
public class PersonViewHolder extends ItemViewHolder<Person> {
//Annotate every field with the ID of the view in the layout.
//The views will automatically be assigned to the fields.
@ViewId(R.id.image_view_person)
ImageView imageViewPerson;
@ViewId(R.id.text_view_name)
TextView textViewName;
@ViewId(R.id.text_view_phone)
TextView textViewPhone;
//Extend ItemViewHolder and call super(view)
public PersonViewHolder(View view) {
super(view);
}
//Override onSetValues() to set the values of the items in the views.
@Override
public void onSetValues(Person person, PositionInfo positionInfo) {
imageViewPerson.setImageResource(person.getResDrawableId());
textViewName.setText(person.getName());
textViewPhone.setText(person.getPhoneNumber());
}
}
If you define the ViewHolder
as an inner class, it must be static
so that the EasyAdapter
can instantiate it.
/*
Create an EasyAdapter by passing a Context, your ItemViewHolder class and the list of items.
Alternatively, you can create an EasyAdapter only with a Context and an ItemViewHolder class and set
the list of items later on.
*/
mListView.setAdapter(new EasyAdapter<Person>(
this,
PersonViewHolder.class,
DataProvider.getListPeople()));
//Same as above but use a EasyRecyclerAdapter instead of EasyAdapter
mRecyclerView.setAdapter(new EasyRecyclerAdapter<Person>(
this,
PersonViewHolder.class,
DataProvider.getListPeople()));
See demo app for a full working example.
Sometimes you need to notify your Activity
or Fragment
about an action that happened in your view holder, for example, you need to set the title of the Activity
when a button that is in the view holder is clicked. From version 1.4.+ this is quite easy to implement by passing a listener or callback to the view holder through the adapter. See the example below:
//Implement the listener.
private PersonViewHolder.PersonListener mListener = new PersonViewHolder.PersonListener() {
public onButtonClicked(Person person) {
setTitle(person.getName());
}
}
//Set the listener when creating the EasyRecyclerAdapter (same for EasyAdapter)
mRecyclerView.setAdapter(new EasyRecyclerAdapter<Person>(
this,
PersonViewHolder.class,
DataProvider.getListPeople(),
mListener));
@LayoutId(R.layout.person_item_layout)
public class PersonViewHolder extends ItemViewHolder<Person> {
@ViewId(R.id.button)
Button button;
//Implement onSetListeners and set a click listener in the button.
@Override
public void onSetListeners() {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Get your custom listener and call the method.
PersonListener listener = getListener(PersonListener.class);
if (listener != null) {
listener.onButtonClicked(getItem());
}
}
}
}
//Define your custom interface
public interface PersonListener {
public void onButtonClicked(Person person);
}
}
If you are using Proguard you need to add the following rules to proguard-rules.pro
:
-keepattributes *Annotation*
-keepclassmembers class * extends uk.co.ribot.easyadapter.ItemViewHolder {
public <init>(...);
}
./gradlew :demo:installDebug
./gradlew :library:build
Copyright 2014 Ribot Ltd.
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.