Search in sources :

Example 1 with SectionAdapter

use of com.chad.baserecyclerviewadapterhelper.adapter.SectionAdapter in project BaseRecyclerViewAdapterHelper by CymChad.

the class SectionUseActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_section_uer);
    setBackBtn();
    setTitle("Section Use");
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
    mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    mData = DataServer.getSampleData();
    SectionAdapter sectionAdapter = new SectionAdapter(R.layout.item_section_content, R.layout.def_section_head, mData);
    mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

        @Override
        public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
            MySection mySection = mData.get(position);
            if (mySection.isHeader)
                Toast.makeText(SectionUseActivity.this, mySection.header, Toast.LENGTH_LONG).show();
            else
                Toast.makeText(SectionUseActivity.this, mySection.t.getName(), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
            Toast.makeText(SectionUseActivity.this, "onItemChildClick" + position, Toast.LENGTH_LONG).show();
        }
    });
    mRecyclerView.setAdapter(sectionAdapter);
}
Also used : MySection(com.chad.baserecyclerviewadapterhelper.entity.MySection) OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) SectionAdapter(com.chad.baserecyclerviewadapterhelper.adapter.SectionAdapter) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 View (android.view.View)1 SectionAdapter (com.chad.baserecyclerviewadapterhelper.adapter.SectionAdapter)1 MySection (com.chad.baserecyclerviewadapterhelper.entity.MySection)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 OnItemClickListener (com.chad.library.adapter.base.listener.OnItemClickListener)1