Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android UI layout Onclick listener

i have one layout like this enter image description here

when click in layer1,layer 2 get invisible but when i click on layer2 it do not go to invisible. i use the following code,but it's not working,when i click layer2 it also go to invisible, any idea to get visible of layer2 when i click layer2.

 RelativeLayout layout1=(RelativeLayout)findViewById(R.id.hidebg);
         final RelativeLayout layout=(RelativeLayout)findViewById(R.id.hidelayer);
         layout1.setOnClickListener(new OnClickListener() 
         {

            @Override
            public void onClick(View v)
            {
                if(layout.getVisibility()==0)
            {
                layout.setVisibility(4);
            }
            else
            {
                layout.setVisibility(0);
            }

            }
        }); 
like image 456
appukrb Avatar asked Jan 02 '13 10:01

appukrb


2 Answers

Add event listener on the second layout

layout.setOnClickListener(new OnClickListener() 
         {

            @Override
            public void onClick(View v)
            {
                if(i==0)
                {
                    layout.setVisibility(4);
                    i=1;
                }
                else
                {
                    layout.setVisibility(0);
                    i=0;
                }

            }
        }); 

Then check.

like image 174
Chinmoy Debnath Avatar answered Sep 19 '22 06:09

Chinmoy Debnath


set layer2 as visible by default and use this code :

layer1.setOnClickListener(new OnClickListener() 
         {

            @Override
            public void onClick(View v)
            {
                if(layer2.getvisibility==View.VISIBLE)
                {
                    layer2.setVisibility(View.GONE);

                }
                else
                {
                    layer2.setVisibility(View.VISIBLE);

                }

            }
        }); 
like image 45
Nipun Gogia Avatar answered Sep 22 '22 06:09

Nipun Gogia