Home > Software engineering >  problem with setVisibility when swithching between two ImageView elements in Java
problem with setVisibility when swithching between two ImageView elements in Java

Time:06-02

    imageView1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view)
        {
            if(imageViewGet1.getDrawable() != null){
                imageView1.setVisibility(View.INVISIBLE);
                imageViewGet1.setVisibility(View.VISIBLE);
            }
            OpenGallery1();

        }
    });
    imageView2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view)
        {
            if(imageViewGet2.getDrawable() != null){
                imageView2.setVisibility(View.INVISIBLE);
                imageViewGet2.setVisibility(View.VISIBLE);
            }
            OpenGallery2();

        }
    });

when I run the code and open galley to pick new photo, after that, the imageView with the old one still appear how I can fix that so when I choose new image, the imageView1 disappear and imageViewGet appear with the new Image.

CodePudding user response:

try to use

imageView1.setVisibility(View.GONE);

if are views overlapping (one is in front of second).

.setVisibility(View.INVISIBLE);

just makes view invisible, but doesn't hide it.

If this won't help, you may can use Shared Preferences to store bool with image (in)visibility state.

CodePudding user response:

I tried this :

imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view)
            {
                OpenGallery1();

                    imageView1.setVisibility(View.INVISIBLE);
                    imageViewGet1.setVisibility(View.VISIBLE);
                if(imageViewGet1.getDrawable()==null){
                    imageView1.setVisibility(View.VISIBLE);
                }
            }
        });

and it works fine.

  • Related