use of com.yanzhenjie.recyclerview.sample.adapter.MainAdapter in project SwipeRecyclerView by yanzhenjie.
the class MenuFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(getContext(), R.color.divider_color)));
mRecyclerView.setOnItemClickListener(mItemClickListener);
mRecyclerView.setSwipeMenuCreator(mSwipeMenuCreator);
mRecyclerView.setOnItemMenuClickListener(mItemMenuClickListener);
MainAdapter menuAdapter = new MainAdapter(getContext());
mRecyclerView.setAdapter(menuAdapter);
List<String> dataList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
dataList.add("我是第" + i + "个。");
}
menuAdapter.notifyDataSetChanged(dataList);
}
use of com.yanzhenjie.recyclerview.sample.adapter.MainAdapter in project SwipeRecyclerView by yanzhenjie.
the class DefaultActivity 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 GridLayoutManager(this, 2));
mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
// RecyclerView Item点击监听。
mRecyclerView.setOnItemClickListener(mItemClickListener);
// 使用默认的加载更多的View。
mRecyclerView.useDefaultLoadMore();
// 加载更多的监听。
mRecyclerView.setLoadMoreListener(mLoadMoreListener);
mAdapter = new MainAdapter(this);
mRecyclerView.setAdapter(mAdapter);
// 请求服务器加载数据。
loadData();
}
use of com.yanzhenjie.recyclerview.sample.adapter.MainAdapter 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.sample.adapter.MainAdapter 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