0

Good day! It is necessary to add a button to delete the imageview (picture). I do not know how to do it. Thx for help =3

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == 1 && null != data) {
        decodeUri(data.getData());
    }
    if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {

        ImageView image = (ImageView)findViewById(R.id.photka);


        Bitmap photo = (Bitmap) data.getExtras().get("data");


        image.setImageBitmap(photo);

    }
}

https://i.stack.imgur.com/CAlDG.png https://i.stack.imgur.com/CAlDG.png

3 Answers3

0

You can remove the ImageView with any of the below options

  1. You can set the visibility of the ImageView to Gone when button is clicked like this

    final ImageView image = (ImageView)findViewById(R.id.photka);
    
    Button removeImageButton = (Button)findViewById(R.id.Button_id);
    removeImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            image.setVisibility(View.GONE);
        }
    });
    
  2. You can remove the ImageView from its parent View like this

    final ViewGroup parent = (ViewGroup)findViewById(R.id.root_parent);
    
    final ImageView image = (ImageView)findViewById(R.id.photka);
    
    Button removeImageButton = (Button)findViewById(R.id.Button_id);
    removeImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            parent.removeView(image);
        }
    });
    
Inducesmile
  • 2,475
  • 1
  • 17
  • 19
0

add code for my activity

ImageView close = (ImageView)findViewById(R.id.close) ; ImageView image = (ImageView)findViewById(R.id.photka);

image.setImageBitmap(bitmap); close.setVisibility(View.VISIBLE);

0

final ImageView image = (ImageView)findViewById(R.id.photka); final ImageView close = (ImageView)findViewById(R.id.close) ;

        Bitmap photo = (Bitmap) data.getExtras().get("data");


        image.setImageBitmap(photo); 
        image.setVisibility(View.VISIBLE);   
        close.setVisibility(View.VISIBLE); 
        close.setOnClickListener(new View.OnClickListener() {  
            @Override
            public void onClick(View v) {
                image.setVisibility(View.GONE);
                close.setVisibility(View.GONE);
                return;
            }
        });

need add remove from stack together with Visibility.Gone