use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.
the class MenuCardActivity 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;
List<String> dataList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
dataList.add("我是第" + i + "个菜单");
}
mMenuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
// 布局管理器。
mMenuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mMenuRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.set(10, 10, 10, 10);
}
});
MenuCardAdapter menuCardAdapter = new MenuCardAdapter(dataList);
menuCardAdapter.setOnItemClickListener(onItemClickListener);
mMenuRecyclerView.setAdapter(menuCardAdapter);
}
use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView 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);
}
use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.
the class DragSwipeFlagsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mActionBar = getSupportActionBar();
assert mActionBar != null;
mActionBar.setDisplayHomeAsUpEnabled(true);
mDataList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
if (i == 0) {
mDataList.add("我不能被拖拽,也不能滑动删除。");
} else {
mDataList.add("我是第" + i + "个。");
}
}
SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
// 布局管理器。
menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// 添加分割线。
menuRecyclerView.addItemDecoration(new ListViewDecoration());
// 这个就不用添加菜单啦,因为滑动删除和菜单是冲突的。
mMenuAdapter = new MenuAdapter(mDataList);
mMenuAdapter.setOnItemClickListener(onItemClickListener);
menuRecyclerView.setAdapter(mMenuAdapter);
// 开启长安拖拽。
menuRecyclerView.setLongPressDragEnabled(true);
// 开启滑动删除。
menuRecyclerView.setItemViewSwipeEnabled(true);
// 监听拖拽,更新UI。
menuRecyclerView.setOnItemMoveListener(onItemMoveListener);
menuRecyclerView.setOnItemMovementListener(onItemMovementListener);
menuRecyclerView.setOnItemStateChangedListener(mOnItemStateChangedListener);
}
use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.
the class DragGridMenuActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mActionBar = getSupportActionBar();
assert mActionBar != null;
mActionBar.setDisplayHomeAsUpEnabled(true);
mContext = this;
mDataList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
mDataList.add("我是第" + i + "个。");
}
SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
// 布局管理器。
menuRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
// 添加分割线。
menuRecyclerView.addItemDecoration(new ListViewDecoration());
// 为SwipeRecyclerView的Item创建菜单就两句话,不错就是这么简单:
// 设置菜单创建器。
menuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
// 设置菜单Item点击监听。
menuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
mMenuAdapter = new MenuAdapter(mDataList);
mMenuAdapter.setOnItemClickListener(onItemClickListener);
menuRecyclerView.setAdapter(mMenuAdapter);
// 开启拖拽,就这么简单一句话。
menuRecyclerView.setLongPressDragEnabled(true);
// 监听拖拽,更新UI。
menuRecyclerView.setOnItemMoveListener(onItemMoveListener);
// 拖拽和侧滑删除时,手指状态监听。
menuRecyclerView.setOnItemStateChangedListener(mOnItemStateChangedListener);
}
use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.
the class DragListMenuActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mActionBar = getSupportActionBar();
assert mActionBar != null;
mActionBar.setDisplayHomeAsUpEnabled(true);
mContext = this;
mDataList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
mDataList.add("我是第" + i + "个。");
}
SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
// 布局管理器。
menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// 添加分割线。
menuRecyclerView.addItemDecoration(new ListViewDecoration());
// 为SwipeRecyclerView的Item创建菜单就两句话,不错就是这么简单:
// 设置菜单创建器。
menuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
// 设置菜单Item点击监听。
menuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
mMenuAdapter = new MenuAdapter(mDataList);
mMenuAdapter.setOnItemClickListener(onItemClickListener);
menuRecyclerView.setAdapter(mMenuAdapter);
// 开启拖拽,就这么简单一句话。
menuRecyclerView.setLongPressDragEnabled(true);
// 监听拖拽,更新UI。
menuRecyclerView.setOnItemMoveListener(onItemMoveListener);
menuRecyclerView.setOnItemStateChangedListener(mOnItemStateChangedListener);
}
Aggregations