Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imageview visibility in Android

In the following code how to hide the image at the start of the APP.So when the user enters the password then show it back again

package com.app.myapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class MyappActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView.setVisibilty(View.INVISIBLE);
    Button btn=(Button) findViewById(R.id.enter);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String prepwd="password";
            EditText  et=(EditText) findViewById(R.id.pwd);
            if(et.getText().toString().equalsIgnoreCase(prepwd))
            {
                ImageView iv=(ImageView) findViewById(R.id.im1);
            }

        }
    });
}
}
like image 902
Naveen Avatar asked Jun 22 '11 19:06

Naveen


People also ask

What is ImageView in android?

ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics. drawable.

Can ImageView display video?

You can add ImageView and VideoView in RelativeLayout and set ImageView to invisible and VideoView to visible and vice-versa and you can play video on onClick.

What code in kotlin can be used to hide image?

You can use setVisibility() method to hide / show the imageView in android studio.


1 Answers

You can modify the visibility of a view with view.setVisibility(x);, where x is View.INVISIBLE, View.VISIBLE, or View.GONE.

You should probably define the image as invisible in your layout XML... android:visibility="invisible"

You can't set visibility on ImageView as your code shows, you must findViewById() to get the view to set visibility on. You seem to be doing that with your iv variable already, so just call the setVisibility() method on it.

like image 129
mah Avatar answered Nov 16 '22 03:11

mah