0

Functionality:

On click of button want to show image And when i clicked the image the image should be dissapear(i use View.GONE for that).

Layout: I relative layout one button and one image on that button but in activity on create method i make image view gone so that i can click on button.

Problem: First time when i click button it works perfectly i.e image appear and on click of image it dissapear.(for that i use View.visible and View.gone respectively). But when i try to click on button second time it will not show image.

I think the image view only get gone but actually image is still there that's why may be button not clickable.So what to do that i can get button clickable.Any help will be appreciated. Thank you...

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings1);
    img = (ImageView) findViewById(R.id.imageView4);
    btn = (Button) findViewById(R.id.btn);
    img.setVisibility(View.GONE);
 }

btn.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
                   img.setVisiblity(View.VISIBLE);
        }
    }

img.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
                   img.setVisiblity(View.GONE);
        }
    }
2
  • can you post the codes,so that we can help you better Feb 11, 2013 at 6:45
  • check whether click event is working or not. check by keeping log inside button click Feb 11, 2013 at 7:14

2 Answers 2

0

Problem is that,

When you use the view.setVisiblity(View.GONE); the view is no longer available for click events. You should use View.Invisible for that

however if you are trying to make the click effect of button, then you should use xml selector

hope it helps

0

Give it a try

    btn.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
                   img.setVisiblity(View.VISIBLE);
                   btn.setVisiblity(View.GONE);

        }
    }

img.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
                   img.setVisiblity(View.GONE);
                   btn.setVisiblity(View.VISIBLE);
        }
    }

I hope it will be helpful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.