adapter适配器点击条目删除
例:
//将数据与界面进行绑定的操作 @Override public void onBindViewHolder(ViewHolder viewHolder, final int position) {viewHolder.item_img.setImageURI(datas.get(position).getPicUrl()); //获取图片,Fresco viewHolder.mTextView.setText(datas.get(position).getTitle());viewHolder.itemView.setOnClickListener(new View.OnClickListener() {@Override public void onClick(View view) {/** * 点击条目删除 */ AlertDialog.Builder builder = new AlertDialog.Builder(context);builder.setIcon(R.mipmap.ic_launcher);builder.setTitle("我是对话框");builder.setMessage("我是对话框的内容");builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Override public void onClick(DialogInterface dialog, int which) {Toast.makeText(context, "点击了取消按钮", Toast.LENGTH_SHORT).show();dialog.dismiss();}});builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Override public void onClick(DialogInterface dialog, int which) {Toast.makeText(context, "点击了确定的按钮", Toast.LENGTH_SHORT).show();dialog.dismiss();//移除数据 datas.remove(position);//条目刷新 notifyDataSetChanged();}});AlertDialog dialog = builder.create();dialog.show();}});}
本文链接:https://my.lmcjl.com/post/1358.html
展开阅读全文
4 评论