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();
}
Aggregations