开发者

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 onCr开发者_Python百科eate(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜