Search in sources :

Example 1 with DividerItemDecoration

use of com.jcodecraeer.xrecyclerview.XRecyclerView.DividerItemDecoration in project XRecyclerView by jianghejie.

the class ItemDecorationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mRecyclerView = (XRecyclerView) this.findViewById(R.id.recyclerview);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(layoutManager);
    Drawable dividerDrawable = ContextCompat.getDrawable(this, R.drawable.divider_sample);
    mRecyclerView.addItemDecoration(mRecyclerView.new DividerItemDecoration(dividerDrawable));
    mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
    mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
    mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
    View header = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup) findViewById(android.R.id.content), false);
    mRecyclerView.addHeaderView(header);
    mRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {

        @Override
        public void onRefresh() {
            refreshTime++;
            times = 0;
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    listData.clear();
                    for (int i = 0; i < 15; i++) {
                        listData.add("item" + i + "after " + refreshTime + " times of refresh");
                    }
                    mAdapter.notifyDataSetChanged();
                    mRecyclerView.refreshComplete();
                }
            }, // refresh data here
            1000);
        }

        @Override
        public void onLoadMore() {
            if (times < 2) {
                new Handler().postDelayed(new Runnable() {

                    public void run() {
                        for (int i = 0; i < 15; i++) {
                            listData.add("item" + (1 + listData.size()));
                        }
                        mRecyclerView.loadMoreComplete();
                        mAdapter.notifyDataSetChanged();
                    }
                }, 1000);
            } else {
                new Handler().postDelayed(new Runnable() {

                    public void run() {
                        for (int i = 0; i < 9; i++) {
                            listData.add("item" + (1 + listData.size()));
                        }
                        mRecyclerView.setNoMore(true);
                        mAdapter.notifyDataSetChanged();
                    }
                }, 1000);
            }
            times++;
        }
    });
    listData = new ArrayList<String>();
    for (int i = 0; i < 15; i++) {
        listData.add("item" + i);
    }
    mAdapter = new MyAdapter(listData);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.refresh();
}
Also used : Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(com.jcodecraeer.xrecyclerview.XRecyclerView.DividerItemDecoration) XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) View(android.view.View) XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 XRecyclerView (com.jcodecraeer.xrecyclerview.XRecyclerView)1 DividerItemDecoration (com.jcodecraeer.xrecyclerview.XRecyclerView.DividerItemDecoration)1