Reputation: 11471
I have set up an ImageView in main.xml, if I want to access it from my View class and make it visible = false, how can I do this programatically?
Thank you
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
theView = new GameView(this);
theView.setBackgroundResource(R.layout.main);
setContentView(theView);
Upvotes: 7
Views: 6700
Reputation: 40168
Suppose you have a ImageView
called imageView
.
Now access the imageView
like
imageView=(ImageView) findViewById(R.id.your_image_view);
Now when you are trying to hide the imageView
just use imageView.setVisibility(View.INVISIBLE);
Hope this will help you
Upvotes: 1
Reputation: 40391
ImageView myView = (ImageView) findViewById(R.id.myView);
myView.setVisibility (android.View.INVISIBLE);
http://developer.android.com/reference/android/view/View.html#INVISIBLE
http://developer.android.com/reference/android/view/View.html#findViewById%28int%29
Upvotes: 1
Reputation: 11571
Use this property in the xml of that Imageview
android:visibility="visible"
and change the visibility programatically like this on some particular event:
image.setVisibility(ImageView.GONE)
where image is the instance of that imageview received through findViewById()
Upvotes: 1
Reputation: 3465
First you should retrieve a link to this view object. Than set visibility property of this object to View.INVISIBLE
ImageView imageView = (ImageView)findViewById(R.id.image_view);
imageView.setVisibility(View.INVISIBLE);
Upvotes: 1
Reputation: 1667
For example, in your layout xml file, there is a imageview1
<ImageView
android:id="@+id/imageview1"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
in your java src,
ImageView img=(ImageView)findViewById(R.id.imageview1);
img.setVisibility(View.GONE);
img.setVisibility(View.VISIBLE);
img.setVisibility(View.INVISIBLE);
you can google the difference between View.Gone and View.VISIBLE
Upvotes: 9