-1

At the click of a button, I set the visibility of some Layout. Now when the button is clicked again I want to put all Layouts invisible. How can I do?

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    getActivity().getMenuInflater().inflate(R.menu.menu_graf, menu);
    super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.grf:
        lista.setVisibility(View.GONE);
        chartContainer.setVisibility(View.VISIBLE);
        lista_c.setVisibility(View.VISIBLE);




            return true;

            default:
            return super.onOptionsItemSelected(item);

    }

    }
user3608814
  • 561
  • 1
  • 8
  • 23
  • Can you post your layout file which contains the Views you want to hide? – G.T. Jun 18 '14 at 16:34
  • You could try setting up an IF statement. `If this = true then set visibility to visible and set this = false Else If this = false then set visibility to not visible and set this = true Else show error message` – CodeMonkey Jun 18 '14 at 16:38

1 Answers1

0

If the view is visible at first, you could use a boolean variable to know when to hide and when to show your view. For example (Pseudocode):

visible = true;

onclickEvent{
    if visible == true{
         visible = false
         view.setVisibility(View.Gone)
    }
    else {
        visible = true
        view.setVisibility(View.VISIBLE)
    }
}
Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79