title: GridView item list selector for multiple items not working in Android
body: <p>I want to draw selector on long press as shown in the picture. When I do long press on one item, the CAB menu is activated. But the list selector indicator goes off once after clicking. I want that list selectors to be active till the CAB menu is active for allowing multiple selection. And the color should toggle if I do double tap. This code works as a flicker when I click on it. Any one faced similar thing? Is there a hack to bring this functionality?</p>
  
  <p>Gridview with multiple selection:</p>
  
  <p><img src="https://i.stack.imgur.com/pWdNP.png" alt="enter image description here"></p>
  
  <p>GridView setchoice in my OnCreate:</p>
  
  <pre><code>gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
  gridView.setMultiChoiceModeListener(new MultiChoiceModeListener());
  </code></pre>
  
  <p>This is working fine:</p>
  
  <pre><code>gridView.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View v,
              int position, long id) {
  
      ImageView iv = (ImageView) v
                          .findViewById(R.id.imageview2);
                  ViewGroup gridChild = (ViewGroup) gridView
                          .getChildAt(position);
                  ViewGroup gridGrandChild = (ViewGroup) gridChild
                          .getChildAt(0);
                  ViewGroup gridGreatGrandChild = (ViewGroup) gridGrandChild
                          .getChildAt(0);
                  int childSize = gridGreatGrandChild.getChildCount();
                  if (iv.getId() == gridGreatGrandChild.getChildAt(1)
                          .getId()) {
                      if (iv.getVisibility() == 4)
                          iv.setVisibility(View.VISIBLE);
                      else
                          iv.setVisibility(View.INVISIBLE);
                  }
  }});
  </code></pre>
  
  <p>I am trying to implement the same code inside the MultiChoiceModeListener() class after the CAB menu is activated. Copied the same code inside </p>
  
  <pre><code>public void onItemCheckedStateChanged(ActionMode mode, int position,
              long id, boolean checked) {
  }
  </code></pre>
  
  <p>method. But I am unable to access the elements inside the viewgroup. But I am able to access the GridView in whole. But not the individual child inside the Grid.</p>
  
  <p>Here is my gridview layout:</p>
  
  <pre><code>    &lt;GridView
              android:id="@+id/grid_view"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:columnWidth="190dp"
              android:drawSelectorOnTop="true"
              android:choiceMode="multipleChoice"
              android:horizontalSpacing="3dp"
              android:listSelector="@drawable/list_selector"
              android:numColumns="auto_fit"
              android:paddingRight="4dp"
              android:stretchMode="spacingWidthUniform"
              android:verticalSpacing="3dp" &gt;
          &lt;/GridView&gt;
  </code></pre>
  
  <p>Each item in the GridView is constructed with this layout:
     
      </p>
  
  <pre><code>&lt;FrameLayout
      android:id="@+id/frameLayout1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" &gt;
  
      &lt;RelativeLayout
          android:id="@+id/relativelayout"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" &gt;
  
          &lt;ImageView
              android:id="@+id/imageview"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" &gt;
          &lt;/ImageView&gt;
  
          &lt;ImageView
              android:id="@+id/imageview2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/imageview"
              android:layout_alignLeft="@+id/imageview"
              android:layout_alignRight="@+id/imageview"
              android:layout_alignTop="@+id/imageview"   
              android:visibility="invisible"
               android:background="#76f9a49c"            
               &gt;
          &lt;/ImageView&gt;
      &lt;/RelativeLayout&gt;
  
      &lt;ImageView
          android:id="@+id/tagimage"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="top|right"
          android:layout_marginRight="-4dp"
          android:src="@drawable/tag"
          android:visibility="invisible" /&gt;
  
      &lt;ImageView
          android:id="@+id/countimage"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom|right"
          android:layout_marginBottom="8dp"
          android:layout_marginRight="5dp"
          android:src="@drawable/dealcount_overlay"
          android:visibility="invisible" /&gt;
  
      &lt;TextView
          android:id="@+id/count"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom|right"
          android:layout_marginBottom="11dp"
          android:layout_marginRight="24dp"
          android:text="100"
          android:textColor="#fff"
          android:visibility="invisible" &gt;
      &lt;/TextView&gt;
  
      &lt;ProgressBar
          android:id="@+id/progressbar"
          style="@android:style/Widget.ProgressBar.Small"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true"
          android:layout_gravity="center"
          android:visibility="visible" /&gt;
  &lt;/FrameLayout&gt;
  
  &lt;TextView
      android:id="@+id/textView_nodata"
      android:layout_width="wrap_content"
      android:layout_height="150dp"
      android:layout_below="@+id/frameLayout1"
      android:layout_centerHorizontal="true"
      android:text="No data available. Try different query!"
      android:textAppearance="?android:attr/textAppearanceLarge"
      android:visibility="gone" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Here is my list_selector.xml:</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  &lt;item android:drawable="@color/gridviewlistselector" android:state_focused="true" android:state_pressed="false"/&gt;
  &lt;item android:state_focused="true"&gt;&lt;shape&gt;
          &lt;solid android:color="#66000000" /&gt;
      &lt;/shape&gt;&lt;/item&gt;
  &lt;item android:state_selected="true"&gt;&lt;shape&gt;
          &lt;solid android:color="#66000000" /&gt;
      &lt;/shape&gt;&lt;/item&gt;
  &lt;item android:state_pressed="true"&gt;&lt;shape&gt;
          &lt;solid android:color="#66000000" /&gt;
      &lt;/shape&gt;&lt;/item&gt;
  &lt;item android:state_enabled="false" android:state_focused="true"&gt;&lt;shape&gt;
          &lt;solid android:color="#66000000" /&gt;
      &lt;/shape&gt;&lt;/item&gt;
  
  &lt;/selector&gt;
  </code></pre>
  
  <p>How can I achieve the functionality? I am getting stuck at this. I tried various combinations on Selectors. But nothing seems to be working for me. Do I need to provide any other detail? </p>