SwipeMenuRecyclerView的使用,侧滑删除

依赖

compile 'com.yanzhenjie:recyclerview-swipe:1.1.2'

布局

<com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView
   android:id="@+id/swipe_recycler_view"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_marginBottom="@dimen/dp10"/>
 
  

activity

swipeRecyclerView.setSwipeMenuCreator(mSwipeMenuCreator);
swipeRecyclerView.setSwipeMenuItemClickListener(mMenuItemClickListener);
swipeRecyclerView.setLayoutManager(new LinearLayoutManager(this));
swipeRecyclerView.setItemAnimator(new DefaultItemAnimator());
swipeRecyclerView.setAdapter(my_AttentionAdapter);
private SwipeMenuCreator mSwipeMenuCreator = new SwipeMenuCreator() {
@Override
   public void onCreateMenu(SwipeMenu swipeMenu, SwipeMenu swipeMenu1, int i) {
int width = getResources().getDimensionPixelSize(R.dimen.dp70);

// 1. MATCH_PARENT 自适应高度,保持和Item一样高;
       // 2. 指定具体的高,比如80;
       // 3. WRAP_CONTENT,自身高度,不推荐;
       int height = ViewGroup.LayoutParams.MATCH_PARENT;
SwipeMenuItem addItem;
addItem = new SwipeMenuItem(My_AttentionActivity.this)
.setBackground(R.color.red_bg_zhifu)
.setText("删除")
.setTextColor(Color.WHITE)
.setWidth(width)
		.setHeight(height);
 
  
        swipeMenu1.addMenuItem(addItem); // 添加菜单到左侧。
   }
};
private SwipeMenuItemClickListener mMenuItemClickListener = new SwipeMenuItemClickListener() {
@Override
   public void onItemClick(SwipeMenuBridge swipeMenuBridge) {
swipeMenuBridge.closeMenu();
int direction = swipeMenuBridge.getDirection(); // 左侧还是右侧菜单。
       int adapterPosition = swipeMenuBridge.getAdapterPosition(); // RecyclerView的Item的position。
       int menuPosition = swipeMenuBridge.getPosition(); // 菜单在RecyclerView的Item中的Position。
       //一个弹出框的dialog的显示
       new DialogUtil(My_AttentionActivity.this).showConfirmDialog( "", "是否删除此关注?",
new DialogInterface.OnClickListener() {

@Override
                   public void onClick(DialogInterface dialog, int which) {
//点击删除调用的删除接口
                       guanzhuPrester.getData(list1.get(adapterPosition).getShopInfo().getShop_id(),list1.get(adapterPosition).getCollect_focus_subscribe_id());
dialog.dismiss();
}
},
 
  
 new DialogInterface.OnClickListener() {

@Override
                   public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}

} );
}
};



你可能感兴趣的:(SwipeMenuRecyclerView的使用,侧滑删除)