Skip to content Skip to sidebar Skip to footer

How To Hide Imagebutton?

I have 1 imageButton and i want to hide that button after 5sec in oncreate method. Can anyone please help me

Solution 1:

onCreate(){
  newSleepTask().execute();
}

privateclassSleepTaskextendsAsyncTask{
  protectedvoiddoInBackground(){
    Thread.sleep(5000);
  }
  protectedvoidonPostExecute(){
    yourImageButton.setVisiblity(View.INVISIBLE);
  }
}

Solution 2:

ImageButton inherits from View so you can always use:

imageButton.setVisibility(View.INVISIBLE);

In order to have the view disappear after x amount of time you can use a handler

Handler handler = new Handler();
handler.postDelayed( new Runnable() {

   publicvoidrun(){
       imageButton.setVisibility(View.INVISIBLE);
   } 

}, 5000);//delayed 5 secs

Ensure to call this after you are done with everything of the view and after setContentView or onViewCreated (for fragments) is called

Solution 3:

imageButton.setVisible(View.INVISIBLE); or imageButton.setVisible(View.GONE);

Post a Comment for "How To Hide Imagebutton?"