RecyclerView的增删改,shap分割线

//适配器
//删除
public void removeData(int position){
list.remove(position);
notifyItemRemoved(position);
notifyDataSetChanged();
}

//添加
public void addData(int position){
list.add(position,list.get(position));
notifyItemInserted(position+1);
}

//修改
public void updateData(int position){
//list.add(position,list.get(position));
//notifyItemRangeChanged(position,1);
//list.set(position,list.get(position));
//notifyItemChanged(position);
list.clear();
notifyDataSetChanged();
}

//清空
public void onClear(){
list.clear();
notifyDataSetChanged();
}

//主界面
adapter.setRecycleOnClick(new RecycleViewAdapter.RecycleitemClick() {
@Override
public void onItemClick(View view, int position) {
//adapter.removeData(position);
//adapter.addData(position);
adapter.updateData(position);
Toast.makeText(MainActivity.this, position + “”, Toast.LENGTH_SHORT).show();
}
});

//自定义shape
//渐变色

<?xml version="1.0" encoding="utf-8"?>



//主界面
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
//瀑布流
//StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
//staggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this,DividerItemDecoration.VERTICAL);
dividerItemDecoration.setDrawable(ContextCompat.getDrawable(this,R.drawable.fen));
recycle.addItemDecoration(dividerItemDecoration);
recycle.setLayoutManager(linearLayoutManager);

猜你喜欢

转载自blog.csdn.net/weixin_42791904/article/details/84035815