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