Search in sources :

Example 6 with DefaultItemDecoration

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());
}
Also used : MainAdapter(com.yanzhenjie.recyclerview.sample.adapter.MainAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) DefaultItemDecoration(com.yanzhenjie.recyclerview.widget.DefaultItemDecoration) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) View(android.view.View) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 7 with DefaultItemDecoration

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();
}
Also used : MainAdapter(com.yanzhenjie.recyclerview.sample.adapter.MainAdapter) DefaultItemDecoration(com.yanzhenjie.recyclerview.widget.DefaultItemDecoration) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

DefaultItemDecoration (com.yanzhenjie.recyclerview.widget.DefaultItemDecoration)7 ActionBar (androidx.appcompat.app.ActionBar)6 Toolbar (androidx.appcompat.widget.Toolbar)6 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)4 SwipeRecyclerView (com.yanzhenjie.recyclerview.SwipeRecyclerView)4 MainAdapter (com.yanzhenjie.recyclerview.sample.adapter.MainAdapter)4 View (android.view.View)3 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)2 OnItemClickListener (com.yanzhenjie.recyclerview.OnItemClickListener)2 ExpandedAdapter (com.yanzhenjie.recyclerview.sample.adapter.ExpandedAdapter)2 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)1 ArrayList (java.util.ArrayList)1