Search in sources :

Example 1 with TestBean

use of la.xiong.androidquick.demo.bean.TestBean in project AndroidQuick by ddnosh.

the class Network2Fragment method initViewsAndEvents.

@Override
protected void initViewsAndEvents() {
    DialogUtil.showLoadingDialog(mContext, "加载中...");
    mTestBeanList = new ArrayList<>();
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mRecyclerView.setHasFixedSize(true);
    mCommonAdapter = new CommonAdapter<TestBean>(getActivity(), R.layout.item_common_adapter_2, mTestBeanList) {

        @Override
        public void convert(CommonViewHolder holder, final TestBean bean) {
            holder.setText(R.id.tv_login, bean.getLogin());
            holder.setText(R.id.tv_id, bean.getId() + "");
            holder.setImageResourceWithGlide(R.id.iv_avatar, bean.getAvatar_url());
            holder.setOnClickListener(R.id.ll_rv_common_adapter_item, new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    LogUtil.d(TAG, "onItemClick");
                    ToastUtil.showToast(bean.getLogin() + " clicked!");
                    bean.setLogin(bean.getLogin() + " clicked!");
                    notifyDataSetChanged();
                }
            });
        }
    };
    mRecyclerView.setAdapter(mCommonAdapter);
    mCompositeSubscription = new CompositeSubscription();
    mRetrofitManager = new RetrofitManager();
    Subscription subscription = mRetrofitManager.createApi(MyApplication.getInstance().getApplicationContext(), TestApis.class).getOctocat("https://api.github.com/repos/octocat/Hello-World/contributors").subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseSubscriber<List<TestBean>>() {

        @Override
        public void onNext(List<TestBean> list) {
            DialogUtil.dismissLoadingDialog(mContext);
            LogUtil.i(TAG, list.toString());
            // 不能这样赋值:mTestBeanList = list;
            // 方法一
            // mTestBeanList.clear();
            // mTestBeanList.addAll(list);
            // mCommonAdapter.notifyDataSetChanged();
            // 方法二
            mCommonAdapter.update(list);
        }

        @Override
        public void onError(Throwable e) {
            super.onError(e);
            DialogUtil.dismissLoadingDialog(mContext);
        }
    });
    mCompositeSubscription.add(subscription);
}
Also used : CommonViewHolder(la.xiong.androidquick.ui.adapter.CommonViewHolder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) RetrofitManager(la.xiong.androidquick.network.RetrofitManager) TestBean(la.xiong.androidquick.demo.bean.TestBean) CompositeSubscription(rx.subscriptions.CompositeSubscription) ArrayList(java.util.ArrayList) List(java.util.List) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BindView (butterknife.BindView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TestBean (la.xiong.androidquick.demo.bean.TestBean)1 RetrofitManager (la.xiong.androidquick.network.RetrofitManager)1 CommonViewHolder (la.xiong.androidquick.ui.adapter.CommonViewHolder)1 Subscription (rx.Subscription)1 CompositeSubscription (rx.subscriptions.CompositeSubscription)1