简体   繁体   English

如何更新ArrayList<Bitmap> 照片删除后?

[英]how to update ArrayList <Bitmap> after photo deletion?

So I am populating my Bitmap ArrayList (photos) by adding images through gallery and camera photos and then saves the array of names into database and images into the storage.因此,我通过通过图库和相机照片添加图像来填充我的位图 ArrayList(照片),然后将名称数组保存到数据库中,将图像保存到存储中。 In the ImageAdapter class if I remove an image from the array list then without saving the list it successfully removes the image from the storage but if I click the save button then it did not remove the image from my internal phone storage as my Bitmap ArrayList (photos) does not update.在 ImageAdapter 类中,如果我从数组列表中删除一个图像,然后没有保存列表,它会成功地从存储中删除该图像,但是如果我单击保存按钮,它并没有将图像从我的内部手机存储中删除为我的 Bitmap ArrayList(照片)不更新。 How can I update my Arraylist of Bitmap in the main class (fragment) before saving?如何在保存之前更新主类(片段)中的位图数组列表?

Save function保存功能

public void saveNotes() {

   if (!Modify) {
       if (titulo.getText().toString().length() > 0) {
           if (!base.buscarNota(titulo.getText().toString())) {
               String almostSameText = Html.toHtml(texto.getEditableText()).toString();
               if (bp != null) {
                   Util.saveToInternalStorage(context, bp, ArrayImageName, photos);
                   Notas notas = new Notas(titulo.getText().toString().trim(), almostSameText, getFecha(), stringForArray);
                   base.insertarNota(notas);
               } else {
                   Notas notas = new Notas(titulo.getText().toString().trim(), almostSameText, getFecha(), null);
                   base.insertarNota(notas);
               }
               getActivity().onBackPressed();
           } else {
               Alerta alerta = new Alerta(context, context.getResources().getString(R.string.title_existente));
           }
       } else {
           Alerta alerta = new Alerta(context, context.getResources().getString(R.string.title_vacio));
       }
   } else {
       String almostSameText = Html.toHtml(texto.getEditableText()).toString();
       if (bp != null) {
           Util.saveToInternalStorage(context, bp, ArrayImageName, photos);
           base.modificarNota(titulo.getText().toString().trim(), almostSameText, stringForArray, id);
       } else {
           base.modificarNota(titulo.getText().toString().trim(), almostSameText, null, id);
       }
       getActivity().onBackPressed();
       getActivity().overridePendingTransition(R.anim.enter_from_left, R.anim.exit_from_right);
   }

} }

my ImageAdapter Delete bitmap class我的 ImageAdapter 删除位图类

public void showDeletePictureDialog(){
    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(Imagecontext);
    } else {
        builder = new AlertDialog.Builder(Imagecontext);
    }
    builder.setTitle("Delete photo")
            .setMessage("Are you sure you want to delete this photo?")
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // continue with delete
                    ImageFileArrayAfterDelete = EditorFragment.loadImageStrings;
                    String folder_main = "MyImages";
                    File f = new File(Environment.getExternalStorageDirectory().toString(), folder_main);
                    z = new File(f.toString(), Uri.parse(String.valueOf(ImageFileArrayAfterDelete.get(currentPosition))) + ".jpg");
                    ImageName = z.getName();
                    Log.d("TAG_", "Position is: " + currentPosition + " File name is: " + ImageName);
                    bpAdapter.remove(currentPosition);
                    ImageFileArrayAfterDelete.remove(currentPosition);
                    toSingleString();
                    notifyItemRemoved(currentPosition);
                    notifyItemRangeChanged(currentPosition, bpAdapter.size());
                    z.delete();
                }
            })

You can achieve this just by doing this after deleting the item from your list您只需在从列表中删除项目后执行此操作即可实现此目的

    myList.removeAt(position)
    myAdapter.notifyDataSetChanged()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM