开源中国系列一:一行代码实现开源中国资讯页面

自定义控件

联网

工具

数据库

源码分析相关面试题

Activity相关面试题

Service相关面试题

与XMPP相关面试题

与性能优化相关面试题

与登录相关面试题

与开发相关面试题

与人事相关面试题

开源项目:https://github.com/open-android/BaseRecyclerAndAdapter

《开源中国系列一:一行代码实现开源中国资讯页面》

使用步骤

1. 在project的build.gradle添加如下代码(如下图)

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

2. 在Module的build.gradle添加依赖

 compile 'com.github.open-android:BaseRecyclerAndAdapter:0.4.8'
 compile 'com.jakewharton:butterknife:8.4.0'
 annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

3. 添加权限

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

4. 在Application的onCreate()中复制如下代码,记得在manifest.xml中注册Application。

  ItheimaHttp.init(this, "http://www.oschina.net/");//baseUrl格式:"http://xxxxxx/"

5. 在XML当中复制如下代码

  <android.support.v4.widget.SwipeRefreshLayout
      android:id="@+id/swipe_refresh_layout"
      android:layout_width="match_parent"
       android:layout_height="match_parent">

                 <org.itheima.recycler.widget.ItheimaRecyclerView
                       android:id="@+id/recycler_view"
                       android:layout_width="match_parent"
                       android:layout_height="match_parent"/>
               </android.support.v4.widget.SwipeRefreshLayout>

5. 复制如下代码到JAVA类中

        pullToLoadMoreRecyclerView = new PullToLoadMoreRecyclerView<Bean>(mSwipeRefreshLayout, recyclerView, MyViewHolder.class) {
        @Override
        public int getItemResId() {
            //recylerview item资源id
            return R.layout.item_recylerview;
        }

        @Override
        public String getApi() {
            //接口
            return "action/apiv2/news?pageToken=";
        }

         @Override
        public boolean isMoreData(BaseLoadMoreRecyclerAdapter.LoadMoreViewHolder holder) {
            System.out.println("isMoreData" + holder);

            return true;
        }
    };
  • 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~

  • 欢迎关注微信公众号

微信公众号名称:Android干货程序员

《开源中国系列一:一行代码实现开源中国资讯页面》

    原文作者:马伟奇
    原文地址: https://www.jianshu.com/p/0ae2108205f7
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞