在以下code如何当用户输入的密码,然后回来再次显示隐藏图像在APP.So开始
包com.app.myapp;
进口android.app.Activity;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.ImageView;
进口android.widget.TextView;
公共类MyappActivity延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
ImageView.setVisibilty(View.INVISIBLE);
按钮BTN =(按钮)findViewById(R.id.enter);
btn.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
字符串prepwd =密码;
的EditText等=(EditText上)findViewById(R.id.pwd);
如果(et.getText()的toString()。equalsIgnoreCase(prepwd))
{
ImageView的IV =(ImageView的)findViewById(R.id.im1);
}
}
});
}
}
解决方案
您可以修改视图的能见度 view.setVisibility(X);
,其中x是 View.INVISIBLE
, View.VISIBLE
或 View.GONE
。
您可能应该定义你的布局XML图像作为无形... 安卓知名度=隐形
您不能设置可见性的ImageView作为code所示,您必须 findViewById()
以获得以期建立知名度。你似乎做,以你的 IV
变了,所以只要调用 setVisibility()
方法就可以了。
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 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.