Click here to Skip to main content
15,883,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Did I do something wrong?

well there're 2 button Visible and Invisible button. Click for do that to appear and disappear imageView1

Java
public class MainActivity extends Activity {
	ImageView imgView = (ImageView)findViewById(R.id.imageView1);
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Button btnV = (Button)findViewById(R.id.btnV);
        Button btnInV = (Button)findViewById(R.id.btnInV);
        
        
        btnV.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	imgView.setVisibility(View.VISIBLE);
            }
        });
        btnInV.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	imgView.setVisibility(View.INVISIBLE);
            }
        });
    }
}
Posted
Updated 23-Jun-14 20:24pm
v3
Comments
Sergey Alexandrovich Kryukov 24-Jun-14 2:06am    
Yes, you did a great deal of wrong. You did not explain what is your purpose, what did you want to achieve, what you expected, what did you get instead and why do you feel this is not what you wanted... :-)
—SA
TorstenH. 24-Jun-14 2:37am    
where is the problem? what is the problem? please explain details.

1 solution

You have to initialize the imageView in onCreate:
public class MainActivity extends Activity {
	ImageView imgView;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        imgView = (ImageView)findViewById(R.id.imageView1); // move the line here
        Button btnV = (Button)findViewById(R.id.btnV);
        Button btnInV = (Button)findViewById(R.id.btnInV);
        
        
        btnV.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	imgView.setVisibility(View.VISIBLE);
            }
        });
        btnInV.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	imgView.setVisibility(View.INVISIBLE);
            }
        });
    }
}
 
Share this answer
 
Comments
Eerven 24-Jun-14 2:48am    
It's work thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900