Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change ImageView

Tags:

android

xml

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);
like image 652
user710502 Avatar asked Apr 18 '11 05:04

user710502


Video Answer


2 Answers

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

like image 72
ninikin Avatar answered Oct 19 '22 23:10

ninikin


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);
like image 24
Ilya Izhovkin Avatar answered Oct 19 '22 22:10

Ilya Izhovkin