user2610135
user2610135

Reputation: 71

How to hide a ImageView and show it after 5 second

I want to hide an image and then make it visible after 10-20 seconds.

Here is my code:

public class MainActivity extends Activity  implements OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView imgv1 = (ImageView) findViewById(R.id.cool);
    imgv1.setOnClickListener(this);

    // This is the image which I want to first hide and then show it after few seconds

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}


@Override
public void onClick(View v) {
    Intent startactivity = new Intent(this,signin.class);
    startActivity(startactivity);
}
}

Upvotes: 0

Views: 4110

Answers (2)

znat
znat

Reputation: 13474

in onCreate()

imgv1.setVisibility(View.GONE);
new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        imgv1.setVisibility(View.VISIBLE);
    }
},10 * 1000); // For 10 seconds

Upvotes: 1

Vikrant_Dev
Vikrant_Dev

Reputation: 390

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView imgv1 = (ImageView) findViewById(R.id.cool);

    imgv1.setVisibility(View.INVISIBLE);
        new Handler().postDelayed(new Runnable(){
            public void run() {
                imgv1.setVisibility(View.VISIBLE);
            }
        }, timeInMillis);

    imgv1.setOnClickListener(this);
}

timeInMillis is the time you want to wait before getting back the ImageView as visible.

Upvotes: 4

Related Questions