Search in sources :

Example 1 with GridSectionAverageGapItemDecoration

use of com.chad.baserecyclerviewadapterhelper.decoration.GridSectionAverageGapItemDecoration in project BaseRecyclerViewAdapterHelper by CymChad.

the class SectionQuickUseActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_section_uer);
    setBackBtn();
    setTitle("Quick Section Use");
    mRecyclerView = findViewById(R.id.rv_list);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
    mRecyclerView.addItemDecoration(new GridSectionAverageGapItemDecoration(10, 10, 20, 15));
    mData = DataServer.getSectionData();
    SectionQuickAdapter adapter = new SectionQuickAdapter(R.layout.item_section_content, R.layout.def_section_head, mData);
    adapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
            MySection mySection = mData.get(position);
            if (mySection.isHeader()) {
                Tips.show((String) mySection.getObject());
            } else {
                Video video = (Video) mySection.getObject();
                Tips.show(video.getName());
            }
        }
    });
    adapter.setOnItemChildClickListener(new OnItemChildClickListener() {

        @Override
        public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
            Tips.show("onItemChildClick: " + position);
        }
    });
    mRecyclerView.setAdapter(adapter);
}
Also used : MySection(com.chad.baserecyclerviewadapterhelper.entity.MySection) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) Video(com.chad.baserecyclerviewadapterhelper.entity.Video) GridSectionAverageGapItemDecoration(com.chad.baserecyclerviewadapterhelper.decoration.GridSectionAverageGapItemDecoration) SectionQuickAdapter(com.chad.baserecyclerviewadapterhelper.adapter.SectionQuickAdapter) OnItemChildClickListener(com.chad.library.adapter.base.listener.OnItemChildClickListener) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

View (android.view.View)1 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 SectionQuickAdapter (com.chad.baserecyclerviewadapterhelper.adapter.SectionQuickAdapter)1 GridSectionAverageGapItemDecoration (com.chad.baserecyclerviewadapterhelper.decoration.GridSectionAverageGapItemDecoration)1 MySection (com.chad.baserecyclerviewadapterhelper.entity.MySection)1 Video (com.chad.baserecyclerviewadapterhelper.entity.Video)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 OnItemChildClickListener (com.chad.library.adapter.base.listener.OnItemChildClickListener)1 OnItemClickListener (com.chad.library.adapter.base.listener.OnItemClickListener)1