Search in sources :

Example 1 with MenuViewTypeAdapter

use of com.yanzhenjie.swiperecyclerview.adapter.MenuViewTypeAdapter in project SwipeRecyclerView by yanzhenjie.

the class MenuViewTypeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    mContext = this;
    // 这里只是模拟数据,模拟Item的ViewType,根据ViewType决定显示什么菜单,到时候你可以根据你的数据来决定ViewType。
    mViewTypeBeanList = new ArrayList<>();
    for (int i = 0, j = 0; i < 30; i++, j++) {
        ViewTypeBean viewTypeBean = new ViewTypeBean();
        if (j == 0) {
            viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_NONE);
            viewTypeBean.setContent("我没有菜单");
        } else if (j == 1) {
            viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_SINGLE);
            viewTypeBean.setContent("我有1个菜单");
        } else if (j == 2) {
            viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_MULTI);
            viewTypeBean.setContent("我有2个菜单");
        } else if (j == 3) {
            viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_LEFT);
            viewTypeBean.setContent("我的左边有菜单,右边没有");
            j = -1;
        }
        mViewTypeBeanList.add(viewTypeBean);
    }
    SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
    menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    menuRecyclerView.addItemDecoration(new ListViewDecoration());
    menuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
    menuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
    MenuViewTypeAdapter menuAdapter = new MenuViewTypeAdapter(mViewTypeBeanList);
    menuAdapter.setOnItemClickListener(onItemClickListener);
    menuRecyclerView.setAdapter(menuAdapter);
}
Also used : ListViewDecoration(com.yanzhenjie.swiperecyclerview.view.ListViewDecoration) SwipeMenuRecyclerView(com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView) MenuViewTypeAdapter(com.yanzhenjie.swiperecyclerview.adapter.MenuViewTypeAdapter) ViewTypeBean(com.yanzhenjie.swiperecyclerview.entity.ViewTypeBean) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ActionBar (android.support.v7.app.ActionBar)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Toolbar (android.support.v7.widget.Toolbar)1 SwipeMenuRecyclerView (com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView)1 MenuViewTypeAdapter (com.yanzhenjie.swiperecyclerview.adapter.MenuViewTypeAdapter)1 ViewTypeBean (com.yanzhenjie.swiperecyclerview.entity.ViewTypeBean)1 ListViewDecoration (com.yanzhenjie.swiperecyclerview.view.ListViewDecoration)1