Search in sources :

Example 1 with FirstItem

use of com.hpu.baserecyclerviewadapter.sample.multi.FirstItem in project BaseRecyclerViewAdapter by donghan0912.

the class MultiTypeFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swip_refresh);
    refreshLayout.setEnabled(false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    list = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        list.add(new FirstItem("第" + i + "条数据"));
        list.add(new SecondItem("第" + i + "条数据"));
        if (i == 0) {
            list.add(new ThirdItem(R.drawable.luoluo_1));
        } else if (i == 1) {
            list.add(new ThirdItem(R.drawable.luoluo_2));
        } else if (i == 2) {
            list.add(new ThirdItem(R.drawable.luoluo_3));
        } else if (i == 3) {
            list.add(new ThirdItem(R.drawable.luoluo_4));
        } else if (i == 4) {
            list.add(new ThirdItem(R.drawable.luoluo_5));
        } else if (i == 5) {
            list.add(new ThirdItem(R.drawable.luoluo_6));
        }
    }
    final BaseRecyclerViewAdapter baseRecyclerViewAdapter = new BaseRecyclerViewAdapter();
    recyclerView.setAdapter(baseRecyclerViewAdapter);
    baseRecyclerViewAdapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Toast.makeText(getContext(), position + "", Toast.LENGTH_SHORT).show();
        }
    });
    baseRecyclerViewAdapter.setOnItemLongClickListener(new BaseRecyclerViewAdapter.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(View view, int position) {
            Toast.makeText(getContext(), position + "", Toast.LENGTH_SHORT).show();
            return false;
        }
    });
    baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_loading));
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_error) {

                @Override
                public void onBindViewHolder(BaseViewHolder holder, int position) {
                    holder.setOnClickListener(R.id.retry, new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            baseRecyclerViewAdapter.setStatusItem(new SimpleItem(R.layout.layout_loading));
                            new Handler().postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    baseRecyclerViewAdapter.setData(list);
                                }
                            }, 3000);
                        }
                    });
                }
            });
        }
    }, 3000);
}
Also used : BaseViewHolder(com.hpu.baserecyclerviewadapter.BaseViewHolder) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ThirdItem(com.hpu.baserecyclerviewadapter.sample.multi.ThirdItem) SecondItem(com.hpu.baserecyclerviewadapter.sample.multi.SecondItem) FirstItem(com.hpu.baserecyclerviewadapter.sample.multi.FirstItem) RecyclerView(android.support.v7.widget.RecyclerView) BaseRecyclerViewAdapter(com.hpu.baserecyclerviewadapter.BaseRecyclerViewAdapter) SimpleItem(com.hpu.baserecyclerviewadapter.SimpleItem)

Aggregations

Handler (android.os.Handler)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 BaseRecyclerViewAdapter (com.hpu.baserecyclerviewadapter.BaseRecyclerViewAdapter)1 BaseViewHolder (com.hpu.baserecyclerviewadapter.BaseViewHolder)1 SimpleItem (com.hpu.baserecyclerviewadapter.SimpleItem)1 FirstItem (com.hpu.baserecyclerviewadapter.sample.multi.FirstItem)1 SecondItem (com.hpu.baserecyclerviewadapter.sample.multi.SecondItem)1 ThirdItem (com.hpu.baserecyclerviewadapter.sample.multi.ThirdItem)1