[ACCEPTED]-How can I hide/show an element when a button is pressed?-hide

Accepted answer
Score: 16

well just take the reference of the TableLayout 2 by using findViewById(int) in the onClickListener(). once you have the object 1 of TableLayout, call setVisibility(View.VISIBLE)

Score: 14
TableLayout tl = (TableLayout)findeViewById(R.id.yourtablelayout);

tl.setVisibility(View.VISIBLE);

Something like that within your onClick() method 1 should do the trick.

Score: 6

Try:

TableLayout table;
Button button;
table = (TableLayout) findViewById (R.id.tablelayout1);
button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {

        // View list = (View)findViewById(R.id.myviewId); 
        tbleview.setVisibility(View.INVISIBLE); 

    }
});

Hope this works.

0

Score: 0

Try this in MainActivity class :

  TextView textview;

/* onClick 3 method of show button */

  public void show(View view){
    textview.setVisibility(View.VISIBLE);

}

/* onClick method 2 of hide button */

public void hide(View view){
    textview.setVisibility(View.INVISIBLE);
}

and try this in onCreate 1 method :

    textview = (TextView) findViewById(R.id.textview);

More Related questions