0

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);
}
}
njzk2
  • 38,969
  • 7
  • 69
  • 107
user2610135
  • 71
  • 2
  • 7
  • possible duplicate of [How to call a method after a delay](http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay) – njzk2 May 23 '14 at 21:02

2 Answers2

4
@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.

Vikrant_Dev
  • 430
  • 2
  • 15
1

in onCreate()

imgv1.setVisibility(View.GONE);
new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        imgv1.setVisibility(View.VISIBLE);
    }
},10 * 1000); // For 10 seconds
s23
  • 43
  • 2
znat
  • 13,144
  • 17
  • 71
  • 106