Search in sources :

Example 1 with PersonViewHolder

use of com.jude.dome.viewholder.PersonViewHolder in project EasyRecyclerView by Jude95.

the class RefreshAndMoreActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_loadmore);
    top = (FloatingActionButton) findViewById(R.id.top);
    recyclerView = (EasyRecyclerView) findViewById(R.id.recyclerView);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    DividerDecoration itemDecoration = new DividerDecoration(Color.GRAY, Util.dip2px(this, 16f), Util.dip2px(this, 72), 0);
    itemDecoration.setDrawLastItem(false);
    recyclerView.addItemDecoration(itemDecoration);
    recyclerView.setAdapterWithProgress(adapter = new RecyclerArrayAdapter<Person>(this) {

        @Override
        public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
            return new PersonViewHolder(parent);
        }
    });
    adapter.setMore(R.layout.view_more, this);
    adapter.setNoMore(R.layout.view_nomore);
    adapter.setOnItemLongClickListener(new RecyclerArrayAdapter.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(int position) {
            adapter.remove(position);
            return true;
        }
    });
    adapter.setError(R.layout.view_error, new RecyclerArrayAdapter.OnErrorListener() {

        @Override
        public void onErrorShow() {
            adapter.resumeMore();
        }

        @Override
        public void onErrorClick() {
            adapter.resumeMore();
        }
    });
    top.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            recyclerView.scrollToPosition(0);
        }
    });
    recyclerView.setRefreshListener(this);
    onRefresh();
}
Also used : DividerDecoration(com.jude.easyrecyclerview.decoration.DividerDecoration) PersonViewHolder(com.jude.dome.viewholder.PersonViewHolder) ViewGroup(android.view.ViewGroup) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EasyRecyclerView(com.jude.easyrecyclerview.EasyRecyclerView) View(android.view.View)

Example 2 with PersonViewHolder

use of com.jude.dome.viewholder.PersonViewHolder in project EasyRecyclerView by Jude95.

the class StickyHeaderActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_loadmore);
    top = (FloatingActionButton) findViewById(R.id.top);
    recyclerView = (EasyRecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    DividerDecoration itemDecoration = new DividerDecoration(Color.GRAY, Util.dip2px(this, 0.5f), Util.dip2px(this, 72), 0);
    itemDecoration.setDrawLastItem(false);
    recyclerView.addItemDecoration(itemDecoration);
    recyclerView.setAdapterWithProgress(adapter = new RecyclerArrayAdapter<Person>(this) {

        @Override
        public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
            return new PersonViewHolder(parent);
        }
    });
    adapter.setMore(R.layout.view_more, this);
    adapter.setNoMore(R.layout.view_nomore, new RecyclerArrayAdapter.OnNoMoreListener() {

        @Override
        public void onNoMoreShow() {
            adapter.resumeMore();
        }

        @Override
        public void onNoMoreClick() {
            adapter.resumeMore();
        }
    });
    adapter.setOnItemLongClickListener(new RecyclerArrayAdapter.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(int position) {
            adapter.remove(position);
            return true;
        }
    });
    adapter.setError(R.layout.view_error, new RecyclerArrayAdapter.OnErrorListener() {

        @Override
        public void onErrorShow() {
            adapter.resumeMore();
        }

        @Override
        public void onErrorClick() {
            adapter.resumeMore();
        }
    });
    // StickyHeader
    StickyHeaderDecoration decoration = new StickyHeaderDecoration(new StickyHeaderAdapter(this));
    decoration.setIncludeHeader(false);
    recyclerView.addItemDecoration(decoration);
    top.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            recyclerView.scrollToPosition(0);
        }
    });
    recyclerView.setRefreshListener(this);
    onRefresh();
}
Also used : DividerDecoration(com.jude.easyrecyclerview.decoration.DividerDecoration) ViewGroup(android.view.ViewGroup) StickyHeaderDecoration(com.jude.easyrecyclerview.decoration.StickyHeaderDecoration) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EasyRecyclerView(com.jude.easyrecyclerview.EasyRecyclerView) View(android.view.View) PersonViewHolder(com.jude.dome.viewholder.PersonViewHolder)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 PersonViewHolder (com.jude.dome.viewholder.PersonViewHolder)2 EasyRecyclerView (com.jude.easyrecyclerview.EasyRecyclerView)2 RecyclerArrayAdapter (com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter)2 DividerDecoration (com.jude.easyrecyclerview.decoration.DividerDecoration)2 StickyHeaderDecoration (com.jude.easyrecyclerview.decoration.StickyHeaderDecoration)1