Search in sources :

Example 11 with ListViewDecoration

use of com.yanzhenjie.swiperecyclerview.view.ListViewDecoration in project SwipeRecyclerView by yanzhenjie.

the class DragTouchListActivity 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++) {
        mDataList.add("我是第" + i + "个。");
    }
    SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
    // 布局管理器。
    menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    // 添加分割线。
    menuRecyclerView.addItemDecoration(new ListViewDecoration());
    // 触摸拖拽的代码在Adapter中:SwipeMenuRecyclerView#startDrag(ViewHolder);
    mDragAdapter = new DragTouchAdapter(menuRecyclerView, mDataList);
    mDragAdapter.setOnItemClickListener(onItemClickListener);
    menuRecyclerView.setAdapter(mDragAdapter);
    // 开启拖拽。
    menuRecyclerView.setLongPressDragEnabled(true);
    // 开启滑动删除。
    menuRecyclerView.setItemViewSwipeEnabled(true);
    // 监听拖拽,更新UI。
    menuRecyclerView.setOnItemMoveListener(onItemMoveListener);
    menuRecyclerView.setOnItemStateChangedListener(mOnItemStateChangedListener);
}
Also used : ListViewDecoration(com.yanzhenjie.swiperecyclerview.view.ListViewDecoration) SwipeMenuRecyclerView(com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView) DragTouchAdapter(com.yanzhenjie.swiperecyclerview.adapter.DragTouchAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ListViewDecoration (com.yanzhenjie.swiperecyclerview.view.ListViewDecoration)11 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)10 Toolbar (android.support.v7.widget.Toolbar)10 MenuAdapter (com.yanzhenjie.swiperecyclerview.adapter.MenuAdapter)8 SwipeMenuRecyclerView (com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView)6 ActionBar (android.support.v7.app.ActionBar)5 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 DragTouchAdapter (com.yanzhenjie.swiperecyclerview.adapter.DragTouchAdapter)1 MenuVerticalAdapter (com.yanzhenjie.swiperecyclerview.adapter.MenuVerticalAdapter)1 MenuViewTypeAdapter (com.yanzhenjie.swiperecyclerview.adapter.MenuViewTypeAdapter)1 ViewTypeBean (com.yanzhenjie.swiperecyclerview.entity.ViewTypeBean)1 ArrayList (java.util.ArrayList)1