title: Changing imageview of a specific item in a listview
body: <p>I want to change an imageview in a listview based on some intent value. To do this I did override the class of simple cursor adapter as the following, </p>
  
  <pre><code>public class NotesAdapter extends SimpleCursorAdapter {
  Intent intent;
  
          public NotesAdapter(Context context, int layout, Cursor c, String[] from, int[] to, Intent i) {
              super(context, layout, c, from, to);
              intent=i;
          }
  
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
             View item =  super.getView(position, convertView, parent);
             ImageView image =  (ImageView) item.findViewById(R.id.icon);
             ImageView image2= (ImageView) item.findViewById(R.id.icon2);
            if (intent.getStringExtra("category")!=null &amp;&amp; intent.getStringExtra("category").equalsIgnoreCase("draft")){
                  image.setVisibility(View.GONE);
                  image2.setVisibility(View.VISIBLE);
              }
              return item;
  
          }
      }
  </code></pre>
  
  <p>In the activity which contains the list view I've defined NotesAdapter and initialize it inside the fragments onCreateView method as the following, </p>
  
  <pre><code>mSimpleCursorAdapter = new NotesAdapter(getActivity(), R.layout.notes_row, null, from, to, getActivity().getIntent());
  </code></pre>
  
  <p>This the code where I initialize the adapter, </p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
  
          View rootView = inflater.inflate(R.layout.fragment_todo_list, container, false);
          mSimpleCursorAdapter = new NotesAdapter(getActivity(), R.layout.notes_row, null, from, to, getActivity().getIntent());
  
          getLoaderManager().initLoader(LOADER_ID, null, this); //once this is done onCreateLoader will be called.
           final ListView listView = (ListView) rootView.findViewById(R.id.notes_list); //findViewById must be called using the rootView because we are inside a fragment.
           listView.addFooterView(new View(getActivity()), null, true);
  
          text=  (TextView) rootView.findViewById(R.id.empty_list);
  
          listView.setAdapter(mSimpleCursorAdapter);
  
  
          if(mSimpleCursorAdapter.isEmpty()) {
              text.setVisibility(View.VISIBLE);
              listView.setEmptyView(text);
              if (getActivity().findViewById (R.id.fragment_container)!=null){
                  getActivity().getSupportFragmentManager().beginTransaction()
                          .replace(R.id. fragment_container, new EmptyEditor()).commit();
              }
          }
          else {
              text.setVisibility(View.INVISIBLE);
          }
  
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long l) {
  
                  Cursor cursor = mSimpleCursorAdapter.getCursor();
                  if (cursor != null &amp;&amp; cursor.moveToPosition(position)) {
  
                      String category= cursor.getString(1);
                      String summary= cursor.getString(2);
                      String description=cursor.getString(3);
                      long id= cursor.getLong(cursor.getColumnIndex(NotesContract.NotesTable._ID));
                      int locationId= cursor.getInt(cursor.getColumnIndex(NotesContract.NotesTable.COLUMN_LOCATION));
  
                      String [] retrievedData= {category, summary, description};
  
  
                      if (getActivity().findViewById (R.id.fragment_container)!=null){
                          //two pane layout
                          listView.setFocusable(true);
                          listView.setSelection(position);
                          Bundle args = new Bundle();
                          args.putStringArray("data",retrievedData);
                          /*args.putInt("update", 1);*/
                          args.putLong("id", id);
                          args.putInt("locationId", locationId);
                          mCallback.onlistElementClicked(args );/*this is available in the parent activity*/
                      }
  
                      else {
                         // one pane layout:
  
                          Intent intent = new Intent(getActivity(), NotesDetails.class);
                          intent.putExtra(Intent.EXTRA_TEXT, retrievedData);
                          /*intent.putExtra("update", 1); */ //to indicate that the query should be update not insert.
                          intent.putExtra("id", id);
                          intent.putExtra("locationId", locationId); //whether it is 0 or 1
                          startActivity(intent);
                      }
  
  
                  }//end outer cursor if.
              }
          });
  
          return rootView;
      }
  </code></pre>
  
  <p>This is the xml file for the row layout, </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                &gt;
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="horizontal"&gt;
          &lt;ImageView
              android:id="@+id/icon"
              android:layout_width="35dp"
              android:layout_height="35dp"
              android:layout_marginRight="8dp"
              android:layout_marginTop="8dp"
              android:src="@drawable/staricon"
              android:visibility="visible"&gt;
          &lt;/ImageView&gt;
  
          &lt;ImageView
              android:id="@+id/icon2"
              android:layout_width="35dp"
              android:layout_height="35dp"
              android:layout_marginRight="8dp"
              android:layout_marginTop="8dp"
              android:src="@drawable/drafticon"
              android:visibility="gone"&gt;
          &lt;/ImageView&gt;
  
  
          &lt;TextView
              android:id="@+id/label"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="6dp"
              android:lines="1"
              android:text="@+id/TextView01"
              android:textSize="24dp"
              &gt;
          &lt;/TextView&gt;
      &lt;/LinearLayout&gt;
  
      &lt;TextView
          android:id="@+id/date"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/&gt; &lt;!--text will be set dynamically --&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>But there is a problem, I only want the image of specific item to be changed (based on the intent value), however when the image is changed all other images are changed. I think this happens because simplecursoradapter uses the same xml file for all items. But, I couldn't find a solution for that, it just keeps changing all imageviews. The item that I need to change its imageview is the last saved item. I have another activity in which the user creates notes, and specify their type (draft or important), when the user clicks save, the item is added to the list and the imageview should be changed based on the type (using intents), this is also applicable when the user edits an existing item in the list. </p>
  
  <p>Can any one please suggest a solution for this problem? </p>
  
  <p>Any help is highly appreciated. </p>
  
  <p>Thank you.</p>