use of com.yanzhenjie.recyclerview.widget.DefaultItemDecoration in project SwipeRecyclerView by yanzhenjie.
the class HeaderViewActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scroll);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
SwipeRecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setOnItemClickListener(this);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
// HeaderView。
View headerView = getLayoutInflater().inflate(R.layout.layout_header, recyclerView, false);
headerView.findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "HeaderView", Toast.LENGTH_SHORT).show();
}
});
recyclerView.addHeaderView(headerView);
// FooterView。
View footerView = getLayoutInflater().inflate(R.layout.layout_footer, recyclerView, false);
footerView.findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "FooterView", Toast.LENGTH_SHORT).show();
}
});
recyclerView.addFooterView(footerView);
MainAdapter mainAdapter = new MainAdapter(this);
recyclerView.setAdapter(mainAdapter);
mainAdapter.notifyDataSetChanged(createDataList());
}
use of com.yanzhenjie.recyclerview.widget.DefaultItemDecoration in project SwipeRecyclerView by yanzhenjie.
the class DefineActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_refresh_loadmore);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
mRefreshLayout = findViewById(R.id.refresh_layout);
// 刷新监听。
mRefreshLayout.setOnRefreshListener(mRefreshListener);
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
mRecyclerView.setOnItemClickListener(mItemClickListener);
// 自定义的核心就是DefineLoadMoreView类。
DefineLoadMoreView loadMoreView = new DefineLoadMoreView(this);
// 添加为Footer。
mRecyclerView.addFooterView(loadMoreView);
// 设置LoadMoreView更新监听。
mRecyclerView.setLoadMoreView(loadMoreView);
// 加载更多的监听。
mRecyclerView.setLoadMoreListener(mLoadMoreListener);
mAdapter = new MainAdapter(this);
mRecyclerView.setAdapter(mAdapter);
// 请求服务器加载数据。
loadData();
}
Aggregations