mvp RecyclerView展示

okhttp依赖compile 'com.squareup.okhttp3:okhttp:3.3.0'
recyclerview依赖compile 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-5'

MainActivity:

public class MainActivity extends BaseActivity implements IbaseView{

    private IMainPersenter iMainPersenter;
    List<BeanDao.DataBean> list = new ArrayList<BeanDao.DataBean>();
    private RecyclerView rv;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            BeanDao ben = (BeanDao) msg.obj;
            List<BeanDao.DataBean> list = ben.getData();
            Myadapter myadapter = new Myadapter(list);
            rv.setAdapter(myadapter);
        }
    };

    @Override
    protected int GetView() {
        return R.layout.activity_main;
    }

    @Override
    void initview() {
        iMainPersenter = new IMainPersenter();
        rv = findViewById(R.id.myrv);
        rv.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));
        rv.setItemAnimator(new DefaultItemAnimator());
       /* SwipeRefreshLayout swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);*/
smart.setRefreshHeader(new BezierRadarHeader(this));
smart.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale));
smart.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        refreshLayout.finishLoadMore(2000);
        cid++;
        Model.getData(MainActivity.this,String.valueOf(cid));
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        lists.clear();
        refreshLayout.finishRefresh(2000);
        cid=1;
        Model.getData(MainActivity.this,String.valueOf(cid));
    }
});
} @Override void initDate() { iMainPersenter.LoadDateview( this); iMainPersenter.getDate( 1); } @Override public void onsucee(BeanDao ben) { Message message = new Message(); message. obj = ben; handler.sendMessage(message); Log. i( "----",ben.getData().get( 0).getNews_title()); }

Base:

public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(GetView());
        initview();
        initDate();
    }

    protected abstract int GetView();
    abstract void initview() ;
    abstract void initDate() ;
}

接口:

public interface HttpCallback {
   void onsuccess(BeanDao dao);
}
httpuntils:
public class Httpuntil {
    HttpCallback callback;
    String string = "http://api.expoon.com/AppNews/getNewsList/type/1/p/";
    public  void doPost(int page, final HttpCallback callback){
    this.callback=callback;
        OkHttpClient build = new OkHttpClient.Builder().build();
        FormBody.Builder builder = new FormBody.Builder();

        FormBody build3 = builder.build();
        Request build1 = new Request.Builder().url(string+page).build();
        Call call = build.newCall(build1);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String string = response.body().string();
                Gson gson = new Gson();
                BeanDao beanDao = gson.fromJson(string, BeanDao.class);

                callback.onsuccess(beanDao);
            }
        });
    }
}
接口:
public interface IbaseView {
void    onsucee(BeanDao ben);
}
布局:
<com.scwang.smartrefresh.layout.SmartRefreshLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/smart"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" >
    <android.support.v7.widget.RecyclerView
        android:id="@+id/rcv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>

</com.scwang.smartrefresh.layout.SmartRefreshLayout>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值