Search in sources :

Example 6 with XRecyclerView

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

the class GridActivity 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);
    GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
    mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
    mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
    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 < 20; 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() {
                        mRecyclerView.loadMoreComplete();
                        for (int i = 0; i < 20; i++) {
                            listData.add("item" + (i + 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" + (i + listData.size()));
                        }
                        mAdapter.notifyDataSetChanged();
                        mRecyclerView.setNoMore(true);
                    }
                }, 1000);
            }
            times++;
        }
    });
    listData = new ArrayList<String>();
    for (int i = 0; i < 20; i++) {
        listData.add("item" + i);
    }
    mAdapter = new MyAdapter(listData);
    mRecyclerView.setAdapter(mAdapter);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) Handler(android.os.Handler) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with XRecyclerView

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

the class LinearActivity 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);
    mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
    mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
    mRecyclerView.setArrowImageView(R.drawable.iconfont_downgrey);
    mRecyclerView.getDefaultRefreshHeaderView().setRefreshTimeVisible(true);
    View header = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup) findViewById(android.R.id.content), false);
    mRecyclerView.addHeaderView(header);
    mRecyclerView.getDefaultFootView().setLoadingHint("自定义加载中提示");
    mRecyclerView.getDefaultFootView().setNoMoreHint("自定义加载完毕提示");
    // if you use setFooterView,the default footerView will unUseful
    // TextView tv = new TextView(this);
    // tv.setText("自定义 footer");
    // mRecyclerView.setFootView(tv, new CustomFooterViewCallBack() {
    // @Override
    // public void onLoadingMore(View yourFooterView) {
    // 
    // }
    // 
    // @Override
    // public void onLoadMoreComplete(View yourFooterView) {
    // 
    // }
    // 
    // @Override
    // public void onSetNoMore(View yourFooterView, boolean noMore) {
    // 
    // }
    // });
    final int itemLimit = 5;
    // When the item number of the screen number is list.size-2,we call the onLoadMore
    mRecyclerView.setLimitNumberToCallLoadMore(2);
    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 < itemLimit; i++) {
                        listData.add("item" + i + "after " + refreshTime + " times of refresh");
                    }
                    mAdapter.notifyDataSetChanged();
                    if (mRecyclerView != null)
                        mRecyclerView.refreshComplete();
                }
            }, // refresh data here
            1000);
        }

        @Override
        public void onLoadMore() {
            Log.e("aaaaa", "call onLoadMore");
            if (times < 2) {
                new Handler().postDelayed(new Runnable() {

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

                    public void run() {
                        for (int i = 0; i < itemLimit; i++) {
                            listData.add("item" + (1 + listData.size()));
                        }
                        if (mRecyclerView != null) {
                            mRecyclerView.setNoMore(true);
                            mAdapter.notifyDataSetChanged();
                        }
                    }
                }, 1000);
            }
            times++;
        }
    });
    listData = new ArrayList<String>();
    mAdapter = new MyAdapter(listData);
    mAdapter.setClickCallBack(new MyAdapter.ItemClickCallBack() {

        @Override
        public void onItemClick(int pos) {
            // a demo for notifyItemRemoved
            listData.remove(pos);
            mRecyclerView.notifyItemRemoved(listData, pos);
        }
    });
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.refresh();
}
Also used : Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) View(android.view.View) XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) Toolbar(android.support.v7.widget.Toolbar)

Example 8 with XRecyclerView

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

the class MultiHeaderActivity 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);
    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);
    View header1 = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup) findViewById(android.R.id.content), false);
    mRecyclerView.addHeaderView(header1);
    header1.setBackgroundColor(0xff556B2F);
    View header2 = LayoutInflater.from(this).inflate(R.layout.recyclerview_header, (ViewGroup) findViewById(android.R.id.content), false);
    mRecyclerView.addHeaderView(header2);
    header2.setBackgroundColor(0xff1874CD);
    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 : XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) XRecyclerView(com.jcodecraeer.xrecyclerview.XRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Handler (android.os.Handler)8 XRecyclerView (com.jcodecraeer.xrecyclerview.XRecyclerView)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 Toolbar (android.support.v7.widget.Toolbar)6 View (android.view.View)5 Drawable (android.graphics.drawable.Drawable)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 RelativeLayout (android.widget.RelativeLayout)1 DividerItemDecoration (com.jcodecraeer.xrecyclerview.XRecyclerView.DividerItemDecoration)1