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);
}
}
});
}
}
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.
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.
You can use setVisibility() method to hide / show the imageView in android studio.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With