8/26/2009

Make invisible a button in an Android Application

If you want in your android application to make a button invisible, place this code in your app:

btnEliminar = (Button) findViewById(R.id.btnEliminar);

btnEliminar.setVisibility(4);


//If you want to make it visible again, change the 4 for a 0.

10 comments:

  1. Where to place the code ?

    ReplyDelete
  2. Why cant use a "1" for invisible or "2" for gone for any view??

    ReplyDelete
  3. Jed said..

    This was very helpful and here how I used it..

    I like to show and hide button onTouch

    1. First when my application loads the button will be hidden..

    2. I touch screen, button is displayed
    nextPage.setVisibility(0);

    3. Touch it again, goes away
    nextPage.setVisibility(4);


    here is what I did...
    //some code

    nextPage.setVisibility(4);

    //Show/hide button
    flipper.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {

    if(event.getAction() == MotionEvent.ACTION_DOWN){

    nextPage.setVisibility(0);


    return true;
    }
    if(event.getAction() == MotionEvent.ACTION_DOWN){

    nextPage.setVisibility(4);

    return true;
    }
    return true;
    }
    });

    ReplyDelete
  4. u should not use integers directly to do this ob. use the pre defined constants VISIBLE , INVISIBLE and GONE instead. They are located inside View so you could have written instead :

    myBtn.setVisibility(View.INVISIBLE);

    This ensures that if the people at google decide that invisble should now be represented by 5 in a later version your program does not crash!

    ReplyDelete
  5. This works perfectly! I wish I knew why it's set to 0 and 4, but at this point I'm just glad it works. Thanks!

    ReplyDelete
  6. This is one of the good product.I think by using this android iPhone application you can get good function.
    Android app developers

    ReplyDelete
  7. This advice is actual interesting, I absolutely enjoyed, I would like get added advice about this, because is actual beautiful, acknowledgment for sharing

    ReplyDelete
  8. Thanks its really intersting, i like it. Thanks again

    ReplyDelete