All Projects → Ericliu001 → Async Expandable List

Ericliu001 / Async Expandable List

Licence: mit

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Async Expandable List

Expandable Recycler View
[DEPRECATED]
Stars: ✭ 1,234 (+458.37%)
Mutual labels:  recyclerview, recyclerview-adapter
Baserecyclerviewadapter
⚡ Fast way to bind RecyclerView adapter and ViewHolder for implementing clean sections.
Stars: ✭ 120 (-45.7%)
Mutual labels:  recyclerview, recyclerview-adapter
Recyclerview Examples
Samples to learn about RecyclerView
Stars: ✭ 87 (-60.63%)
Mutual labels:  recyclerview, recyclerview-adapter
Flap
Flap(灵动),一个基于 RecyclerView 的页面组件化框架。
Stars: ✭ 204 (-7.69%)
Mutual labels:  recyclerview, recyclerview-adapter
Android Rv Swipe Delete
RecyclerView swipe to delete example.
Stars: ✭ 143 (-35.29%)
Mutual labels:  recyclerview, recyclerview-adapter
Elements
⚒ Modular components for RecyclerView development enforcing clean, reusable and testable code, with built-in support for paging and complex hierarchies of data.
Stars: ✭ 75 (-66.06%)
Mutual labels:  recyclerview, recyclerview-adapter
Poweradapter
Adapter for RecyclerView(only 21KB).RecyclerView万能适配器(仅21KB)
Stars: ✭ 112 (-49.32%)
Mutual labels:  recyclerview, recyclerview-adapter
Rendererrecyclerviewadapter
A single adapter with multiple view types for the whole project
Stars: ✭ 1,061 (+380.09%)
Mutual labels:  recyclerview, recyclerview-adapter
Easyrecyclerview
🎞 Easy recyclerview for Android
Stars: ✭ 131 (-40.72%)
Mutual labels:  recyclerview, recyclerview-adapter
Easyadapter
Recyclerview adapter library- Create adapter in just 3 lines of code
Stars: ✭ 122 (-44.8%)
Mutual labels:  recyclerview, recyclerview-adapter
Moretype
new method to build data in RecyclerView with Kotlin!
Stars: ✭ 189 (-14.48%)
Mutual labels:  recyclerview, recyclerview-adapter
Customadapter
RV Adapter 优雅封装,抽取列表模版,可以快速的添加一个列表,使用组装的方式构建Adapter,抽象Cell 角色,负责创建ViewHolder,绑定数据和逻辑处理。Cell为一个独立的组件。
Stars: ✭ 172 (-22.17%)
Mutual labels:  recyclerview, recyclerview-adapter
Groupedrecyclerviewadapter
GroupedRecyclerViewAdapter可以很方便的实现RecyclerView的分组显示,并且每个组都可以包含组头、组尾和子项;可以方便实现多种Type类型的列表,可以实现如QQ联系人的列表一样的列表展开收起功能,还可以实现头部悬浮吸顶功能等。
Stars: ✭ 1,163 (+426.24%)
Mutual labels:  recyclerview, recyclerview-adapter
Flexadapter
The easiest way to use a RecyclerView on Android
Stars: ✭ 80 (-63.8%)
Mutual labels:  recyclerview, recyclerview-adapter
Autorecycleradapter
Automated configuration RecyclerView.Adapter for Android
Stars: ✭ 67 (-69.68%)
Mutual labels:  recyclerview, recyclerview-adapter
Cartlayout
🦄 使用 RecyclerView 实现店铺分组购物车。 高仿京东购物车、高仿淘宝购物车、高仿天猫购物车
Stars: ✭ 101 (-54.3%)
Mutual labels:  recyclerview, recyclerview-adapter
Firestorerecycleradaptersample
Sample Android project using FirestoreRecyclerAdapter
Stars: ✭ 43 (-80.54%)
Mutual labels:  recyclerview, recyclerview-adapter
Recyclerview Concatadapter
Sample to practice RecyclerView ConcatAdapter
Stars: ✭ 47 (-78.73%)
Mutual labels:  recyclerview, recyclerview-adapter
Recyclerview
How to use a recyclerview
Stars: ✭ 121 (-45.25%)
Mutual labels:  recyclerview, recyclerview-adapter
Fastadapter
快速使用的RecyclerView Adapter
Stars: ✭ 170 (-23.08%)
Mutual labels:  recyclerview, recyclerview-adapter

async-expandable-list

Android Arsenal

============ async-expandable-list contains 2 View classes: CollectionView and AsyncExpandableListView.

Demo Demo

Add async-expandable-list to your project

Gradle:

compile 'com.ericliu.asyncexpandablelist:asyncexpandablelist:1.1.0'

Please make sure you have jcenter() in your project's repository. Check build.gradle file under the project's root directory. Add the following lines if they are missing.

allprojects {
    repositories {
        jcenter()
    }
}

Introduction

CollectionView displays a list of headers and sub-items:

  • Header A
    • item a1
    • item a2
  • Header B
    • item b1
    • item b2
    • item b3
  • Header C
    • item c1
    • item c2
    • item c3

AsyncExpandableListView displays a list of headers and loads a sub-list under a header when a header item is clicked. The loading of sub-items can be done asynchronously and there are callbacks to populate the data into the list when it's done loading.

  1. CollectionView in 3 steps

  1. Add the CollectionView to the layout.xml file where you want to display the list (Optional, population the CollectionView class in java has the same result)
<com.ericliu.asyncexpandablelist.CollectionView
        android:id="@+id/collectionView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

  1. Pouplating data
  • find the CollectionView instance and call setCollectionCallbacks() to setup callbacks for the CollectionView, which will be responsible for creating ViewHolders and binding data into the ViewHoders - works the same as the RecyclerView.Adapter except that you don't have to worry about view types.
  • Create a CollectionView.Inventory instance, the Inventory instance represents the whole data structure that's gonna be populated into the list.
public class MainActivity extends Activity implements CollectionViewCallbacks<String, News> {
  private CollectionView<String, News> mCollectionView;
  private CollectionView.Inventory<String, News> inventory;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      mCollectionView = (CollectionView) findViewById(R.id.collectionView);
      mCollectionView.setCollectionCallbacks(this);
      
      // the inventory represent all the whole data structure that's gonna be populated into the list.
      inventory = new CollectionView.Inventory<>();

  • Create InventoryGroup intances and add header item and sub-items into the InventoryGroup instance. Note the the newGroup(int groupOrdinal) method provided in the Inventory class requires an integer parameter: groupOrdinal. All the groups will be displayed in the list in an ascending order on the groupOrdinal. An InventoryGroup represents a header item and all sub-items under that header in the list.
      int groupOrdinal = 0; // groupOrdinal dictates the sequence of groups to be displayed in the list
      CollectionView.InventoryGroup<String, News> group1 = inventory.newGroup(groupOrdinal); 
      
      // creating objects to be populated into the list.
      News news1 = new News();
      ...  
      News news2 = new News(); ......
      .......
      
      // set the header item, in this case, it is simply a String.
      group1.setHeaderItem("Top Stories");
      // add items under this header.
      group1.addItem(news1);
      group1.addItem(news2);
      group1.addItem(news3);
        ....

  • Call updateInventory() to display the data structure we just created
 mCollectionView.updateInventory(inventory);

All done, the list will display the exact header-items structure.

  1. AsyncExpandableListView in 3 steps

  1. add AsyncExpandableListView to layout.xml file where you want to display the expandable list. (Optional, population the AsyncExpandableListView class in java has the same result).
<com.ericliu.asyncexpandablelist.async.AsyncExpandableListView
        android:id="@+id/asyncExpandableCollectionView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
  1. Populating data
  • find the AsyncExpandableListView and call setCallbacks() and supply an AsyncExpandableListViewCallbacks instance to the view. The callbacks will handle the creation of ViewHolders and binding data to the ViewHolders.
public class AsyncActivity extends Activity implements AsyncExpandableListViewCallbacks<String, News> {

  private AsyncExpandableListView<String, News> mAsyncExpandableListView;
  private CollectionView.Inventory<String, News> inventory;


  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_async);
      mAsyncExpandableListView = (AsyncExpandableListView) findViewById(R.id.asyncExpandableCollectionView);
      mAsyncExpandableListView.setCallbacks(this);

  • In particular the void onStartLoadingGroup(int groupOrdinal) method in the AsyncExpandableListViewCallbacks will be triggered on the header item click events, which gives the client a change to trigger loading sub-item data calls. When the call comes back, the client should call the method onFinishLoadingGroup(mGroupOrdinal, items) on the AsyncExpandableListView instance to display the data as well as updating UI.
  • The steps to add groups are the same as CollectionView mentioned above, but we don't need to add sub-items to groups at this point because only headers will be shown in the beginning in an expandable list, as the code snippet showed below:
 inventory = new CollectionView.Inventory<>();

        CollectionView.InventoryGroup<String, News> group1 = inventory.newGroup(0); // groupOrdinal is the smallest, displayed first
        group1.setHeaderItem("Top Stories");


        CollectionView.InventoryGroup<String, News> group2 = inventory.newGroup(2); // 2 is the second smallest ordinal, displayed second
        group2.setHeaderItem("World");


        CollectionView.InventoryGroup<String, News> group3 = inventory.newGroup(3);
        group3.setHeaderItem("Australia");

        CollectionView.InventoryGroup<String, News> group4 = inventory.newGroup(4); 
        group4.setHeaderItem("International");

        CollectionView.InventoryGroup<String, News> group5 = inventory.newGroup(5); 
        group5.setHeaderItem("Businesses");

        CollectionView.InventoryGroup<String, News> group6 = inventory.newGroup(6); 
        group6.setHeaderItem("Technology");

        mAsyncExpandableListView.updateInventory(inventory);

  1. Handle the async calls
  • Making the call to load all sub-items under a header in the method onStartLoadingGroup() in the AsyncExpandableListViewCallbacks.
 @Override
  public void onStartLoadingGroup(int groupOrdinal) {
      new LoadDataTask(groupOrdinal, mAsyncExpandableListView).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
  }
  ```
* When the data come back, call ``` onFinishLoadingGroup(mGroupOrdinal, items); ``` to display data. 
```java
  mAsyncExpandableListView.onFinishLoadingGroup(mGroupOrdinal, items);

References:

Inspired by CollectionView in Google iosche

https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/CollectionView.java

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].