title: How to highlight selected gridview items
body: <p>im using gridview <code>CHOICE_MODE_MULTIPLE_MODAL</code> to select multiple items(images) in my gridview .</p>
  
  <p>I used <code>MultiChoiceModeListener</code> to achieve this, the problem is selected items are not get highlighted </p>
  
  <p>Selector xml:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
     &lt;selector xmlns:android="http://schemas.android.com/apk/res/android" &gt;
     &lt;item android:state_selected="true" android:drawable="@color/green"/&gt;
     &lt;item android:state_pressed="true" 
            android:drawable="@color/blue"/&gt; &lt;!-- pressed state --&gt;
     &lt;item android:state_focused="true" 
            android:drawable="@color/blue"/&gt; &lt;!-- focused state --&gt;
     &lt;item android:drawable="@android:color/transparent"/&gt; &lt;!-- default state --&gt; 
  
     &lt;/selector&gt;
  </code></pre>
  
  <p>When I touch an item it get covered with blue (i think this happens bcoz i used <code>gridView.setDrawSelectorOnTop(true);</code> )...as soon as i lift my finger blue color get removed.   </p>
  
  <p>I want the selected items to get <code>highlighted</code> with <code>semi transparent blue</code> color and it should stay highlighted until I deselect the item.</p>
  
  <p>Java Code: </p>
  
  <pre><code>public class HappyFragment extends ParentFragment {
  
      public HappyImageAdapter imageAdapter;
      private List&lt;ResolveInfo&gt; mApps;
      GridView gridView;
  
       public static HappyFragment newInstance() {
           HappyFragment fragment = new HappyFragment();
           return fragment;
       }
  
       @Override
       public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
  
  //          if ((savedInstanceState != null) &amp;&amp; savedInstanceState.containsKey(KEY_CONTENT)) {
  //            //  mContent = savedInstanceState.getString(KEY_CONTENT);
  //          }
       }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
              View view = inflater.inflate(R.layout.happy_fragment_layout, container, false);
             //  ImageView iv= (ImageView) view.findViewById(R.id.imageView1); 
               gridView = (GridView)view.findViewById(R.id.gvHappy);
  
              // Instance of ImageAdapter Class
               imageAdapter = new HappyImageAdapter(getActivity());
              gridView.setAdapter(imageAdapter);
              gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
              gridView.setMultiChoiceModeListener(new MultiChoiceModeListener());
              gridView.setDrawSelectorOnTop(true);
              gridView.setSelector(getResources().getDrawable(R.drawable.gridview_selector));
  
              gridView.setOnItemLongClickListener(new OnItemLongClickListener() {
  
                  public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) {
                      Toast.makeText(getActivity(), String.valueOf(imageAdapter.mThumbIds[position]), Toast.LENGTH_SHORT).show();
                      return true;
                  }
              }); 
  
              gridView.setOnItemClickListener(new OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View v,int position, long id) {
                      if(BaseActivity.isinint) { // check if any app cares for the result
                          int ImageResourse=imageAdapter.mThumbIds[position];
                      Uri path = Uri.parse("android.resource://dragonflymobile.stickers.lifestickers/" + ImageResourse);
  
                          Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND, path); //Create a new intent. First parameter means that you want to send the file. The second parameter is the URI pointing to a file on the sd card. (openprev has the datatype File)
  
                          ((Activity)getActivity()).setResult(Activity.RESULT_OK, shareIntent); //set the file/intent as result
                          ((Activity)getActivity()).finish(); //close your application and get back to the requesting application like GMail and WhatsApp
                          return; //do not execute code below, not important
                      } else {
                          Intent intent = new Intent(getActivity(), PreviewActivity.class);
                          intent.putExtra("Image Int", imageAdapter.mThumbIds[position]);
                          startActivity(intent);
                      }
                  }
              });
              return view;
          }
  
          @Override
          public void onSaveInstanceState(Bundle outState) {
              super.onSaveInstanceState(outState);
           //   outState.putString(KEY_CONTENT, mContent);
          }
  
          //multi select mode codes
          public class MultiChoiceModeListener implements GridView.MultiChoiceModeListener {
              public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                  mode.setTitle("Select Items");
                  mode.setSubtitle("One item selected");
                  return true;
              }
  
              public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                  return true;
              }
  
              public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                  return true;
              }
  
              public void onDestroyActionMode(ActionMode mode) {
              }
  
              public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
                  int selectCount = gridView.getCheckedItemCount();
                  switch (selectCount) {
                  case 1:
                      mode.setSubtitle("One item selected");
                      break;
                  default:
                      mode.setSubtitle("" + selectCount + " items selected");
                      break;
                  }
              }
  }
  }
  </code></pre>