Java Code Examples for com.github.jdsjlzx.recyclerview.LRecyclerView#refresh()

The following examples show how to use com.github.jdsjlzx.recyclerview.LRecyclerView#refresh() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BilibiliActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this,2));

    mVisitables = getData();
    mMainAdapter = new MainAdapter(new ListTypeFactory(), mVisitables);
    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mMainAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() {
        @Override
        public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
            Object item = mVisitables.get(position);
            return (item instanceof HotList || item instanceof ProductList || item instanceof Category) ? gridLayoutManager.getSpanCount() : 1;
        }
    });

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mRecyclerView.refreshComplete(10);
                }
            },1000);
        }
    });

    mRecyclerView.refresh();
    mRecyclerView.setLoadMoreEnabled(false);
    //是否允许嵌套滑动
    mRecyclerView.setNestedScrollingEnabled(false);

}
 
Example 2
Source File: ExpandableRecyclerViewOneActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);


    mDataAdapter = new CommentExpandAdapter(this,mRecyclerView);
    mDataAdapter.setMode(ExpandableRecyclerAdapter.MODE_ACCORDION);
    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
    mRecyclerView.setArrowImageView(R.drawable.ic_pulltorefresh_arrow);

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            isRefresh = true;
            requestData();
        }
    });

    mRecyclerView.refresh();

    //不要在调用下面代码
    /*mLRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            //ItemModel item = mDataAdapter.getDataList().get(position);
            //AppToast.showShortText(ExpandableRecyclerViewOneActivity.this, item.title);
        }

        @Override
        public void onItemLongClick(View view, int position) {
            //ItemModel item = mDataAdapter.getDataList().get(position);
            //AppToast.showShortText(ExpandableRecyclerViewOneActivity.this, "onItemLongClick - " + item.title);
        }
    });*/

}
 
Example 3
Source File: Nest2RecyclerViewActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);
    mRecyclerView.setNestedScrollingEnabled(false);

    mShopAdapter = new ShopAdapterBase(this,mGoodsList);

    //setLayoutManager must before setAdapter
    GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
    mRecyclerView.setLayoutManager(layoutManager);

    initData();

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mShopAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);
    mShopAdapter.addAll(mItemModels);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setHeight(R.dimen.default_divider_height)
            .setPadding(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addItemDecoration(divider);

    mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() {
        @Override
        public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
            MultipleItem item = mShopAdapter.getDataList().get(position);
            if (item.getItemType() == MultipleItem.LIST) {
                return gridLayoutManager.getSpanCount();
            } else {
                return 1;
            }

        }
    });

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mRecyclerView.refreshComplete(10);
                }
            },1000);
        }
    });

    mRecyclerView.refresh();

    //是否允许嵌套滑动
    mRecyclerView.setNestedScrollingEnabled(false);

}
 
Example 4
Source File: EndlessGridLayoutActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    //setLayoutManager must before setAdapter
    GridLayoutManager manager = new GridLayoutManager(this, 2);
    mRecyclerView.setLayoutManager(manager);

    mDataAdapter = new DataAdapter(this);

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    //设置头部加载颜色
    mRecyclerView.setHeaderViewColor(R.color.colorAccent, R.color.dark ,android.R.color.white);
    //设置底部加载颜色
    mRecyclerView.setFooterViewColor(R.color.colorAccent, R.color.dark ,android.R.color.white);
    //设置底部加载文字提示
    mRecyclerView.setFooterViewHint("拼命加载中","已经全部为你呈现了","网络不给力啊,点击再试一次吧");

    int spacing = getResources().getDimensionPixelSize(R.dimen.dp_4);
    mRecyclerView.addItemDecoration(SpacesItemDecoration.newInstance(spacing, spacing, manager.getSpanCount(), Color.GRAY));

    //根据需要选择使用GridItemDecoration还是SpacesItemDecoration
    GridItemDecoration divider = new GridItemDecoration.Builder(this)
            .setHorizontal(R.dimen.default_divider_padding)
            .setVertical(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();
    //mRecyclerView.addItemDecoration(divider);

    mRecyclerView.setHasFixedSize(true);

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    //设置span,自己可以体验效果
    /*mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() {
        @Override
        public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
            if (position % 4 == 0) {
                return gridLayoutManager.getSpanCount();
            } else {
                return 1;
            }

        }
    });*/


    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            mDataAdapter.clear();
            requestData();
        }
    });

    mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (mCurrentCounter < TOTAL_COUNTER) {
                // loading more
                requestData();
            } else {
                //the end
                mRecyclerView.setNoMore(true);
            }
        }
    });

    mRecyclerView.refresh();

}
 
Example 5
Source File: EndlessStaggeredGridLayoutActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    mDataAdapter = new DataAdapter(this);

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    //setLayoutManager
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager( 2, StaggeredGridLayoutManager.VERTICAL);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    //防止item位置互换
    layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
    mRecyclerView.setLayoutManager(layoutManager);

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            mDataAdapter.clear();
            requestData();
        }
    });

    mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (mCurrentCounter < TOTAL_COUNTER) {
                // loading more
                requestData();
            } else {
                //the end
                mRecyclerView.setNoMore(true);
            }
        }
    });


    mRecyclerView.refresh();

}