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);
}
}
});
}
}
You can modify the visibility of a view with
view.setVisibility(x);, where x isView.INVISIBLE,View.VISIBLE, orView.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 yourivvariable already, so just call thesetVisibility()method on it.