title: ImageView onClickListener()
body: <p>I am having trouble with changing the state of <code>ImageView</code> which marks list items as bookmarked.</p>
  
  <p>People have mentioned to create a new <code>OnClickListener()</code> which I have but when I click on the ImageView it does go to the focused state but when you finish clicking it does not change to the pressed state image. Furthermore, when I click on the list item I notice that the <code>ImageView</code> is focused again. I am not sure what I am missing:</p>
  
  <pre><code>public class DxSimpleCursorAdapter extends SimpleCursorAdapter {
  Context context;
  Activity activity;
  ImageView image;
  
  public DxSimpleCursorAdapter(Context context, int layout, Cursor c,
          String[] from, int[] to) {
      super(context, layout, c, from, to);
      this.context=context;
      this.activity=(Activity) context;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent){
      View view = super.getView(position, convertView, parent);
      long id = getItemId(position);
      final ImageView image = (ImageView) view.findViewById(R.id.fav);
  
      image.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v){
              image.setBackgroundResource(R.drawable.ic_fav);
  
              final Button btn = (Button) v.findViewById(R.id.fav);
              btn.setPressed(true);
          }
      });
      return view;
  }
  }
  </code></pre>
  
  <p>I have created the xml for the ImageView state as follows:</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:drawable="@drawable/btn_star_off_normal"
      android:state_checked="false"
      android:state_window_focused="false" /&gt;
  &lt;item android:drawable="@drawable/btn_star_on_normal"
      android:state_checked="true"
      android:state_window_focused="false" /&gt;
  
  &lt;item android:drawable="@drawable/btn_star_on_pressed"
      android:state_checked="true"
      android:state_pressed="true" /&gt;
  &lt;item android:drawable="@drawable/btn_star_off_pressed"
      android:state_checked="false"
      android:state_pressed="true" /&gt;
  
  &lt;item android:drawable="@drawable/btn_star_on_focused"
      android:state_checked="true"
      android:state_focused="true" /&gt;
  &lt;item android:drawable="@drawable/btn_star_off_focused"
      android:state_checked="false"
      android:state_focused="true" /&gt;
  
  &lt;item android:state_checked="false" android:drawable="@drawable/btn_star_off_normal" /&gt;
  &lt;item android:state_checked="true" android:drawable="@drawable/btn_star_on_normal" /&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>Within my activity I have created the following <code>OnListItemClick()</code> to create a toast message which pops up but also seems to put focus on the <code>ImageView</code>.</p>
  
  <pre><code>    public void onListItemClick(ListView parent, View view, int position, long id) {
      SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();
      Cursor c = (Cursor) getListAdapter().getItem(position);
      String arg = c.getString(c.getColumnIndex("_id"));
      Cursor cursor = db.rawQuery("Select category, subcategory From DiagLookup Where _id = ?",  new String[]{""+arg});
      cursor.moveToFirst();
  
      Context context = getApplicationContext();
      CharSequence text = "Category: " + cursor.getString(cursor.getColumnIndex("category")) + "\nSubcategory: " + cursor.getString(cursor.getColumnIndex("subcategory"));
      int duration = Toast.LENGTH_SHORT;
  
      Toast toast = Toast.makeText(context, text, duration);
      toast.show();
  }
  </code></pre>
  
  <p>CLARIFICATION on what I want to happen:</p>
  
  <p>I have list items which I want to do two things; click on the item and get a toast message and click on a imageview and toggle the imageview to a bookmarked state in image and also in the backend.</p>
  
  <p>At the moment I have the toast message working but the imageview is not entirely working...</p>
  
  <p>I have attached a screenshot of a list item to show how it is setup and explain what is occurring when I click on the various areas.</p>
  
  <p><img src="https://i.stack.imgur.com/gn7T1.png" alt="ListItem with ImageView clickable"></p>
  
  <p>The top list item has been clicked on and held, what I get is the image changes to the focussed but unclicked image as shown in my drawable xml above but when I finish the click the star gets darker grey then the other entries but it does not turn to the clicked state image which is a yellow star. </p>
  
  <p>When I click anywhere else and not on the star then the toast message pops up which is what I intended to occur but I also notice that the star becomes focussed as well. I feel like I am having some inheritance issue and also not getting the state to stick for the ImageView.</p>