1

I am developing a multi select gridview of pictures from gallery.

I have included imageview and checkbox as each grid item.

I need to make the checkbox visible only when i click the select label in actionbar (menu item). Please advice how I can make it work. I am new to android development and any help is appreciated.

chitra
  • 77
  • 9

1 Answers1

1

For any View, you can control whether or not it is visible by using the setVisibility(int) method. The int passed should be one of three values (taken from this question)

  • View.VISIBLE (0): the view is visible.

  • View.INVISIBLE (1): The view is invisible, but it still takes up space for layout purposes.

  • View.GONE (2): the view is gone. Completely hidden, as if the view had not been added

To make that change, you'll need a listener for when the fragment is clicked. It may look something like this:

myFragment.setOnClickListener( new onClickListener(){

  @Override
  public void onClick(View v) {
      myCheckBox.setVisiblity(View.VISIBLE);
  }

});
Community
  • 1
  • 1
Matt
  • 5,404
  • 3
  • 27
  • 39
  • Thank you very much Matt, will try the solution suggested by you. – chitra Mar 03 '16 at 22:00
  • Please up-vote solutions that were helpful and if this (or any other solution that comes up) solves your problem, please mark the answer and accepted :) – Matt Mar 03 '16 at 22:19
  • sorry to ask this, i am new to this.. how can i do that – chitra Mar 03 '16 at 22:40
  • No problem, we were all new once. Next to all answers and questions, there's a number and two arrows (one up and one down). The help menu and then selecting tour will be more explicit, but in general, up vote questions and answers that are helpful, down vote questions and answers that are particularly unhelpful. On questions you ask, next to each other the answers there should be the outline of a check mark. If you feel that answer sufficiently answers your question, you can indicate as the best answer by clicking that check. – Matt Mar 03 '16 at 22:53
  • doesnt seem to be working, can you please suggest how to get hold of the checkbox which is in my adapter class in a fragment onCreateOptionsMenu() method. – chitra Mar 03 '16 at 22:55