{"id":16557919,"url":"https://github.com/tellh/nolistadapter","last_synced_at":"2025-07-16T12:08:22.110Z","repository":{"id":127060887,"uuid":"67983490","full_name":"TellH/NoListAdapter","owner":"TellH","description":"A more elegant and easy way to build an multifunctional adapter for ListView or RecyclerView in Android.","archived":false,"fork":false,"pushed_at":"2016-10-04T11:38:41.000Z","size":3925,"stargazers_count":37,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T20:11:17.959Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TellH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-12T06:51:34.000Z","updated_at":"2023-08-03T06:57:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"fda1c23a-45ea-4b97-8df8-64ba6036483d","html_url":"https://github.com/TellH/NoListAdapter","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/TellH/NoListAdapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FNoListAdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FNoListAdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FNoListAdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FNoListAdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TellH","download_url":"https://codeload.github.com/TellH/NoListAdapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TellH%2FNoListAdapter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265508395,"owners_count":23779134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T20:09:02.669Z","updated_at":"2025-07-16T12:08:22.046Z","avatar_url":"https://github.com/TellH.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NoListAdapter\n[![](https://jitpack.io/v/TellH/NoListAdapter.svg)](https://jitpack.io/#TellH/NoListAdapter)\n\nA more elegant and easy way to build an multifunctional adapter for ListView or RecyclerView in Android.\n###Why NoListAdapter?\nUsing this library, you don't even have to write an adapter for a ListView or RecyclerView. When using RecyclerView， I found it is not convenient and elegant  to realise multi-type item. Moreover, there is no native way to set empty view, header, footer, load more footer and error view in RecyclerView. Although we have many implementations, I think adapter is quite qualified for those task.\n## What it can do?\n- Easy to Add Multi-type item to RecyclerView and ListView.\n- Easy to set empty view in RecyclerView.\n- Easy to add header and footer in RecyclerView.\n- Easy to set Load More Footer in RecyclerView.\n- Easy to show or hide error view in RecyclerView.\n\n\n## How to do?\n### SetUp\nIn project build.gradle\n``` groovy\nallprojects {\n    repositories {\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\nIn app module build.gradle\n``` groovy\ndependencies {\n\t//if you want to use in listview, add this line.\n    compile 'com.github.TellH.NoListAdapter:nolistadapter-lv:1.0.2'\n    //if you want to use in recyclerview, add this line.\n    compile 'com.github.TellH.NoListAdapter:nolistadapter-rv:1.0.2'\n}\n```\n### Quick Start\n1 . Make your data entity class extends DataBean and attach item layout id to it. like:\n``` java\npublic class User extends DataBean {\n    private String login;\n    private int id;\n    //...\n    @Override\n    public int getItemLayoutId(IListAdapter adapter) {\n        return R.layout.item_user;\n    }\n    // setter and getter omitted.\n    //...\n}\n```\n2 . Create ViewBinder and VIewHolder for an item type. \ni.e. for RecyclerView\n``` java\npublic class UserRecyclerViewBinder extends RecyclerViewBinder\u003cUser, UserRecyclerViewBinder.ViewHolder\u003e {\n    @Override\n    public ViewHolder provideViewHolder(View itemView) {\n        return new UserRecyclerViewBinder.ViewHolder(itemView);\n    }\n\n    @Override\n    public void bindView(IListAdapter adapter, UserRecyclerViewBinder.ViewHolder holder, int position, User entity) {\n        holder.tvId.setText(String.valueOf(entity.getId()));\n        holder.tvName.setText(entity.getLogin());\n        holder.tvUrl.setText(entity.getHtml_url());\n    }\n\n    @Override\n    public int getItemLayoutId(IListAdapter adapter) {\n        return R.layout.item_user;\n    }\n\n    protected class ViewHolder extends RecyclerViewBinder.ViewHolder {\n        public TextView tvId;\n        public TextView tvName;\n        public TextView tvUrl;\n        public ViewHolder(View rootView) {\n            super(rootView);\n            this.tvId = findViewById(R.id.tv_id);\n            this.tvName = findViewById(R.id.tv_name);\n            this.tvUrl = findViewById(R.id.tv_url);\n        }\n\n    }\n}\n```\n### \n[Creatre ViewBinder sample for ListView](https://github.com/TellH/NoListAdapter/blob/master/app/src/main/java/com/tellh/nolistadaptersample/lv/UserListViewBinder.java)\n\n3 . Build an Adapter.\n i.e. for RecyclerView\n``` java\n        List\u003cUser\u003e userList = response.getItems();\n        adapter = RecyclerViewAdapter.builder()\n                .displayList(userList)\n                .addItemType(new UserRecyclerViewBinder())\n                .build();\n        list.setAdapter(adapter);\n```\n[Build an Adapter for ListView](https://github.com/TellH/NoListAdapter/blob/master/app/src/main/java/com/tellh/nolistadaptersample/ListViewActivity.java)\n\n### Multi-Type Item\nJust Create DataBean and ViewBinder for each Item type and add it to your Adapter Builder.\n``` java\n        List\u003cUser\u003e userList = response.getItems();\n        List\u003cDataBean\u003e displayList = new ArrayList\u003c\u003e();\n        for (int i = 0; i \u003c userList.size(); i++) {\n            displayList.add(new ImageItem(userList.get(i).getAvatar_url()));\n            displayList.add(userList.get(i));\n        }\n        adapter = RecyclerViewAdapter.builder()\n                .displayList(displayList)\n                .addItemType(new UserRecyclerViewBinder()) //different item type have different ways to bind data to ViewHolder.\n                .addItemType(new ImageItemRecyclerViewBinder())\n                .build();\n```\n### Empty View, Header and Footer\nCreate ViewBinder\n``` java\npublic class EmptyBinder extends EmptyRecyclerViewBinder\u003cEmptyBinder.ViewHolder\u003e\npublic class HeaderBinder extends HeaderRecyclerViewBinder\u003cHeaderBinder.ViewHolder\u003e\npublic class FooterBinder extends FooterRecyclerViewBinder\u003cFooterBinder.ViewHolder\u003e\n```\nAdd it to your Adapter Builder\n``` java\nadapter = RecyclerViewAdapter.builder()\n\t\t\t\t      //...\n                .setEmptyView(new EmptyBinder())\n                .addHeader(new HeaderBinder(\"I am the first header! 我是沙发\"))\n                .addHeader(new HeaderBinder(\"I am the second header! 我是板凳\"))\n                .addFooter(new FooterBinder(\"------I am the footer!------\"))\n                .addFooter(new FooterBinder(\"------我是有底线的！-------\"))\n\t            //...\n                .build();\n```\nIf you just want to show Empty View, use EasyEmptyRecyclerViewBinder\n``` java\n.setEmptyView(new EasyEmptyRecyclerViewBinder(R.layout.empty_view))\n```\n![](https://raw.githubusercontent.com/TellH/NoListAdapter/master/raw/empty_view.gif)\n### Error View\nCreate ViewBinder\n``` java\npublic class ErrorBinder extends ErrorRecyclerViewBinder\u003cErrorBinder.ViewHolder\u003e\n```\nAdd it to your Adapter Builder\n``` java\n.setErrorView(new ErrorBinder(this))\n```\nThen show and hide Error View if you want.\n``` java\nadapter.showErrorView(recyclerView);\nadapter.hideErrorView(recyclerView);\n```\n\n![](https://raw.githubusercontent.com/TellH/NoListAdapter/master/raw/error_view.gif)\n\n### Load More Footer\nCreate Footer ViewBinder, Check out more information in this [sample](https://github.com/TellH/NoListAdapter/blob/master/app/src/main/java/com/tellh/nolistadaptersample/rv/LoadMoreFooterBinderRecycler.java).\n``` java\npublic class LoadMoreFooterBinderRecycler extends FooterRecyclerViewBinder\u003cLoadMoreFooterBinderRecycler.ViewHolder\u003e {\n    @Override\n    protected void bindFooter(IListAdapter adapter, ViewHolder holder, int position) {\n        FooterLoadMoreAdapterWrapper adapterWrapper = (FooterLoadMoreAdapterWrapper) adapter;\n        if (adapter.getDisplayList().size() == 0) {\n            holder.progressBar.setVisibility(View.INVISIBLE);\n            holder.tvFooter.setText(\"No Data\");\n            return;\n        }\n        switch (adapterWrapper.getFooterStatus()) {\n            case PULL_TO_LOAD_MORE:\n                holder.progressBar.setVisibility(View.VISIBLE);\n                holder.tvFooter.setText(toLoadText);\n                break;\n            case LOADING:\n                holder.progressBar.setVisibility(View.VISIBLE);\n                holder.tvFooter.setText(loadingText);\n                break;\n            case NO_MORE:\n                holder.tvFooter.setText(noMoreText);\n                holder.progressBar.setVisibility(View.INVISIBLE);\n                break;\n        }\n        holder.ivFooter.setImageResource(R.mipmap.ic_launcher);\n    }\n    // Remainder omitted\n}\n```\nAdd it to your Adapter Builder:\n``` java\n        adapter = RecyclerViewAdapter.builder()\n                .addHeader(new HeaderBinder(\"I am the first header! 我是沙发\"))\n                .addFooter(new FooterBinder(\"------I am the footer!------\"))\n                .setLoadMoreFooter(new LoadMoreFooterBinderRecycler(), list, new OnReachFooterListener() {\n                    @Override\n                    public void onToLoadMore(int i) {\n                        // to load more data.\n                    }\n                })\n                .build();\n```\nNote: setLoadMoreFooter should be added behind addHeader and addFooter.\n\nWhen getting Refresh or Load More data, just call FooterLoadMoreAdapterWrapper#OnGetData, it will handle pagination for you.\n``` java\n    public void onGetRefreshData() {\n        FooterLoadMoreAdapterWrapper footerLoadMoreAdapterWrapper = (FooterLoadMoreAdapterWrapper) adapter;\n        footerLoadMoreAdapterWrapper.OnGetData(displayList, REFRESH);\n        refreshLayout.setRefreshing(false);\n    }\n\n    public void onGetLoadMoreData(DataBean displayList) {\n        FooterLoadMoreAdapterWrapper footerLoadMoreAdapterWrapper = (FooterLoadMoreAdapterWrapper) adapter;\n        footerLoadMoreAdapterWrapper.OnGetData(displayList, LOAD_MORE);\n    }\n```\n\n![](https://raw.githubusercontent.com/TellH/NoListAdapter/master/raw/load_more.gif)\n\n## How it works?\nNo mater in ListView or RecyclerView, the adapter is in charge of providing view holder and binding data to each item view. Furthermore, different type items with different layout ids should have different data beans and  different ways for databinding. So it would be more fixable and elegant to separate business code of binding data and providing view holder from the adapter. Instead, ViewBinder will handle those task.\n\n![](https://raw.githubusercontent.com/TellH/NoListAdapter/master/raw/principle.png)\n\nDataBean holds the data and an item layout id. With layout id, it provides ViewBinder to bind data to item view in Adapter's method such as onBindViewHolder in RecyclerView and getView in ListView.\n\n![Alt text](https://raw.githubusercontent.com/TellH/NoListAdapter/master/raw/databean.png)\n\n## License\n   Copyright 2016 TellH\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftellh%2Fnolistadapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftellh%2Fnolistadapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftellh%2Fnolistadapter/lists"}