Android 如何从cardview中删除自定义卡

Android 如何从cardview中删除自定义卡,android,Android,我使用自定义卡视图来显示服务器数据。我有一堆卡片,一张一张地出现。所以,我想知道,我应该如何删除整个卡点击删除按钮。 扫描仪图像 以下是适配器代码: public class CardAdapter<M> extends BaseCardAdapter implements View.OnLongClickListener { private List<Model> modelList; private Conte

我使用自定义卡视图来显示服务器数据。我有一堆卡片,一张一张地出现。所以,我想知道,我应该如何删除整个卡点击删除按钮。 扫描仪图像

以下是适配器代码:

    public class CardAdapter<M> extends BaseCardAdapter implements View.OnLongClickListener {
            private List<Model> modelList;
            private Context context;
            TextView tvCount;

            public CardAdapter(List<Model> modelList, Context context, TextView tvCount) {
                this.modelList = modelList;
                this.context = context;
                this.tvCount = tvCount;
            }

            @Override
            public int getCount() {
                return modelList.size();
            }

            @Override
            public int getCardLayoutId() {
                return R.layout.card_item;
            }

            @RequiresApi(api = Build.VERSION_CODES.N)
            @Override
            public void onBindData(final int position, final View cardview) {
        //      if (modelList==null || modelList.size()==0){
        //          return;
        //      }
        //        tvCount.setText((position)+"/"+modelList.size());

                // ImageView imageView=(ImageView)cardview.findViewById(R.id.imageView);
                TextView textView = (TextView) cardview.findViewById(R.id.textView);
                TextView textView1 = (TextView) cardview.findViewById(R.id.textView1);
                TextView textView2 = (TextView) cardview.findViewById(R.id.textView2);
                TextView textView3 = (TextView) cardview.findViewById(R.id.textView3);
                TextView textView4 = (TextView) cardview.findViewById(R.id.textView4);
                TextView textView5 = (TextView) cardview.findViewById(R.id.textView5);
                TextView textView6 = (TextView) cardview.findViewById(R.id.textView6);
                TextView textView7 = (TextView) cardview.findViewById(R.id.textView7);

                final Model model = modelList.get(position);
                //textView.setText ("Name" + ": " +  model.getName());
                String name = "<font color=#FFFFFF>Name:</font>";
                String nameOne = "<font color=#FFFFFF>" + " " + model.getName() + " </font>";
                textView.setText(Html.fromHtml(name + nameOne));

                //textView1.setText("Job Title" + ": " +  model.getJobTitle());
                String job = "<font color=#FFFFFF>Job Title:</font>";
                String jobOne = "<font color=#FFFFFF>" + " " + model.getJobTitle() + " </font>";
                textView1.setText(Html.fromHtml(job + jobOne));

                //textView2.setText("Company" + ": " +  model.getCompany());
                String company = "<font color=#FFFFFF>Company:</font>";
                String companyOne = "<font color=#FFFFFF>" + " " + model.getCompany() + " </font>";
                textView2.setText(Html.fromHtml(company + companyOne));

                //textView3.setText("Telephone" + ": " +  model.getTelephone());
                String telephone = "<font color=#FFFFFF>Telephone:</font>";
                String telephoneOne = "<font color=#FFFFFF>" + " " + model.getTelephone() + " </font>";
                textView3.setText(Html.fromHtml(telephone + telephoneOne));

                //textView4.setText("Mobile" + ": " +  model.getMobile());
                String mobile = "<font color=#FFFFFF>Mobile:</font>";
                String mobileOne = "<font color=#FFFFFF>" + " " + model.getMobile() + " </font>";
                textView4.setText(Html.fromHtml(mobile + mobileOne));

                //textView5.setText("Email" + ": " +  model.getEmail());
                String email = "<font color=#FFFFFF>Email:</font>";
                String emailOne = "<font color=#FFFFFF>" + " " + model.getEmail() + " </font>";
                textView5.setText(Html.fromHtml(email + emailOne));

                //textView6.setText("Address" + ": " +  model.getAddress());
                String address = "<font color=#FFFFFF>Address:</font>";
                String addressOne = "<font color=#FFFFFF>" + " " + model.getAddress() + " </font>";
                textView6.setText(Html.fromHtml(address + addressOne));

                //textView7.setText("Narration" + ": " +  model.getNarration());
                String narration = "<font color=#FFFFFF>Narration:</font>";
                String narrationOne = "<font color=#FFFFFF>" + " " + model.getNarration() + " </font>";
                textView7.setText(Html.fromHtml(narration + narrationOne));

cardview.findViewById(R.id.textView).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Model model = modelList.get(position);

                customDialogAddContactnShare(model);

                return false;
            }
        });

        cardview.findViewById(R.id.textView2).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Model model = modelList.get(position);

                customDialogSearch(model.getCompany());

                return false;
            }
        });

        cardview.findViewById(R.id.textView4).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Model model = modelList.get(position);

                customeDilogMobCallnMsg(model.getMobile());

                return false;
            }
        });

        cardview.findViewById(R.id.textView3).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Model model = modelList.get(position);

                customDilogTeleCallnMsg(model.getTelephone());
                return false;
            }
        });

        cardview.findViewById(R.id.textView5).setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                Model model = modelList.get(position);

                customDialogMail(model.getEmail());

                return false;
            }
        });

        cardview.findViewById(R.id.textView6).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                Model model = modelList.get(position);

                customDialogMapAddress(model.getAddress());

                return false;
            }
        });

        //tvCount.setText(modelList.size());
        //Toast.makeText(context," " + modelList.size(),Toast.LENGTH_SHORT).show();
        // Picasso.with(context).load(model.getImage()).into(imageView);
    }

    @Override
    public boolean onLongClick(View v) {
        return false;
    }
公共类CardAdapter扩展BaseCardAdapter实现View.OnLongClickListener{
私有列表模型列表;
私人语境;
文本视图tvCount;
公共卡适配器(列表模型列表、上下文上下文、文本视图tvCount){
this.modelList=modelList;
this.context=上下文;
this.tvCount=tvCount;
}
@凌驾
public int getCount(){
返回modelList.size();
}
@凌驾
public int getCardLayoutId(){
返回R.layout.card_项;
}
@RequiresApi(api=Build.VERSION\u code.N)
@凌驾
公共无效onBindData(最终整型位置,最终视图cardview){
//如果(modelList==null | | modelList.size()==0){
//返回;
//      }
//setText((位置)+“/”+modelList.size());
//ImageView ImageView=(ImageView)cardview.findViewById(R.id.ImageView);
TextView TextView=(TextView)cardview.findViewById(R.id.TextView);
TextView textView1=(TextView)cardview.findViewById(R.id.textView1);
TextView textView2=(TextView)cardview.findViewById(R.id.textView2);
TextView textView3=(TextView)cardview.findViewById(R.id.textView3);
TextView textView4=(TextView)cardview.findViewById(R.id.textView4);
TextView textView5=(TextView)cardview.findViewById(R.id.textView5);
TextView textView6=(TextView)cardview.findViewById(R.id.textView6);
TextView textView7=(TextView)cardview.findViewById(R.id.textView7);
最终模型=modelList.get(位置);
//textView.setText(“名称”+:“+model.getName());
String name=“name:”;
字符串nameOne=“+”+model.getName()+”;
setText(Html.fromHtml(name+nameOne));
//textView1.setText(“职务“+”:“+model.getJobTitle());
String job=“职务:”;
字符串jobOne=“”+”+model.getJobTitle()+”;
textView1.setText(Html.fromHtml(job+jobOne));
//textView2.setText(“公司”+:“+model.getCompany());
String company=“公司:”;
字符串companyOne=“+”+model.getCompany()+”;
textView2.setText(Html.fromHtml(company+companyOne));
//textView3.setText(“电话”+:“+model.getTelephone());
String telephone=“电话:”;
字符串telephoneOne=“+”+model.getTelephone()+”;
textView3.setText(Html.fromHtml(电话+telephoneOne));
//textView4.setText(“Mobile”+:“+model.getMobile());
String mobile=“mobile:”;
字符串mobileOne=“”+”+model.getMobile()+”;
textView4.setText(Html.fromHtml(mobile+mobileOne));
//textView5.setText(“Email”+:“+model.getEmail());
String email=“电子邮件:”;
字符串emailOne=“+”+model.getEmail()+”;
textView5.setText(Html.fromHtml(email+emailOne));
//textView6.setText(“地址”+:“+model.getAddress());
String address=“地址:”;
字符串addressOne=“+”+模型。getAddress()+”;
textView6.setText(Html.fromHtml(address+addressOne));
//textView7.setText(“旁白”+:“+model.getAttributement());
字符串旁白=“旁白:”;
字符串叙事One=“”+”+model.getAttransation()+”;
textView7.setText(Html.fromHtml(旁白+旁白单));
cardview.findViewById(R.id.textView).setOnLongClickListener(新视图.OnLongClickListener()){
@凌驾
仅长按公共布尔值(视图v){
模型=模型列表.get(位置);
customDialogAddContactnShare(模型);
返回false;
}
});
cardview.findViewById(R.id.textView2).setOnLongClickListener(新视图.OnLongClickListener(){
@凌驾
仅长按公共布尔值(视图v){
模型=模型列表.get(位置);
customDialogSearch(model.getCompany());
返回false;
}
});
cardview.findViewById(R.id.textView4).setOnLongClickListener(新视图.OnLongClickListener(){
@凌驾
仅长按公共布尔值(视图v){
模型=模型列表.get(位置);
customeDilogMobCallnMsg(model.getMobile());
返回false;
}
});
cardview.findViewById(R.id.textView3).setOnLongClickListener(新视图.OnLongClickListener(){
@凌驾
仅长按公共布尔值(视图v){
模型=模型列表.get(位置);
CustomDiLogTelecollNMSG(model.getTelephone());
返回false;
}
});
cardview.findViewById(R.id.textView5).setOnLongClickListener(新视图.OnLongClickListener(){
@凌驾
仅长按公共布尔值(视图v){
模型=模型列表.get(位置);
customDialogMail(model.getEmail());
返回false;
}
});
cardview.findViewById(R.id.textView6).设置长点击列表
private void deletePlace(int position) {
        DBOpenHelper dbOpenHcelper = new DBOpenHelper(context);
        dbOpenHelper.deleteData(arrayList.get(position).getEVENT());
        arrayList.remove(position);
        notifyItemRemoved(position);
        notifyItemRangeChanged(position,arrayList.size());