title: Android Custom ListView CursorAdapter updating the last item
body: <p>I'm having issue with my custom listview (CursorAdapter)</p>
  
  <p>When I click btAdd on 2nd item, it's updating the last list item. And also, when I click an item, it doesn't display this </p>
  
  <pre><code>Log.e("Selected", "" + position);
  </code></pre>
  
  <p>What I wanna do is to update the edittext of the 2nd item or whatever is the selected item.</p>
  
  <p>MainActivity.class</p>
  
  <pre><code>private void initControls(View rootView) {
  
      lv = (ListView) rootView.findViewById(R.id.listView1);
      MyTextView tvHeader = (MyTextView) rootView.findViewById(R.id.tvHeader);
  
      DatabaseHelper dbHelper = new DatabaseHelper(getActivity());
      DBConnector.dbConnect(dbHelper);
  
      cursor = dbHelper.getAllItems(user);
  
      adapterProd = new CustomAdapter(getActivity(), cursor);
      lv.setAdapter(adapterProd);
      adapterProd.notifyDataSetChanged();
  
      lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                                  int position, long id) {
              Log.e("Selected", "" + position);
          }
      });
  
      if(adapterProd.getCount() &lt; 1) {
          tvHeader.setVisibility(View.VISIBLE);
          tvHeader.setText(getResources().getString(R.string.no_saved_items));
      } else {
          tvHeader.setVisibility(View.GONE);
      }
  
  }
  
  class CustomAdapter extends CursorAdapter
  {
      TextView name, price, description;
      EditText etQuantity;
      ImageButton ibAdd, ibSubtract;
      ImageView img;
      LayoutInflater inflater;
  
      @SuppressWarnings("deprecation")
      public CustomAdapter(Context context, Cursor c) {
          super(context, c);
          inflater = LayoutInflater.from(context);
      }
  
      @Override
      public void bindView(final View itemView, Context context, Cursor cursor) {
  
          name = (TextView) itemView.findViewById (R.id.tvName);
          price = (TextView) itemView.findViewById(R.id.tvPrice);
          description = (TextView) itemView.findViewById(R.id.tvDescription);
          etQuantity = (EditText) itemView.findViewById(R.id.etQuantity);
          etQuantity.append(String.valueOf(quantity));
          etQuantity.setSelection(etQuantity.getText().length());
          ibAdd = (ImageButton) itemView.findViewById(R.id.ibAdd);
          ibSubtract = (ImageButton) itemView.findViewById(R.id.ibSubtract);
          img = (ImageView) itemView.findViewById(R.id.imageView);
  
          checkBox = (CheckBox) itemView.findViewById(R.id.checkBox);
  
          final String selected =
                  cursor.getString(
                          cursor.getColumnIndex(Constants.KEY_ID));
  
          checkBox.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  if (((CheckBox) v).isChecked()) {
                      //Case 1
                      Log.e("Selected", "" + selected);
                      itemView.setPressed(true);
                  }
                  else {
                      //case 2
                      Log.e("Deselected", "" + selected);
                      itemView.setPressed(false);
                  }
  
              }
          });
  
          ibAdd.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  quantity++;
                  etQuantity.setText(String.valueOf(quantity));
              }
          });
  
          ibSubtract.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  quantity--;
                  if(quantity &lt; 1) {
                      quantity = 1;
                  }
                  etQuantity.setText(String.valueOf(quantity));
              }
          });
  
  
          if(cursor.getString(
              cursor.getColumnIndex(Constants.KEY_PRODUCT_NAME)) != null) {
              name.setText(cursor.getString(
                  cursor.getColumnIndex(Constants.KEY_PRODUCT_NAME)));
              price.setText(Formatter.formatWithPesoSign(cursor.getString(
                      cursor.getColumnIndex(
                              Constants.KEY_PRODUCT_PRICE))));
              description.setText(cursor.getString(
                  cursor.getColumnIndex(Constants.KEY_PRODUCT_NAME)));
          } else {
              price.setVisibility(View.GONE);
              name.setText(cursor.getString(
                  cursor.getColumnIndex(Constants.KEY_PRODUCT_PARTITION_KEY)));
              description.setText(cursor.getString(
                  cursor.getColumnIndex(Constants.KEY_PRODUCT_ROW_KEY)));
  
              if(ConnectionDetector.hasNetworkConnection(getActivity())) {
                  GetSavedItemAsyncTask task = new GetSavedItemAsyncTask(
                      getActivity(), accessToken, sessionKey,
                      cursor.getString(
                          cursor.getColumnIndex(Constants.KEY_PRODUCT_PARTITION_KEY)),
                      cursor.getString(
                          cursor.getColumnIndex(Constants.KEY_PRODUCT_ROW_KEY)),
                      cursor.getString(
                          cursor.getColumnIndex(Constants.KEY_ID)),
                      user);
                  task.execute();
              }
  
          }
  
          Picasso.with(getActivity())
                  .load(Constants.displayProductThumbnail(Constants.MERCHANT,
                          cursor.getString(
                                  cursor.getColumnIndex(Constants.KEY_PRODUCT_ROW_KEY)), "200"))
                  .placeholder(R.drawable.placeholder)
                  .into(img);
  
  
      }
  
      @Override
      public View newView(Context context, Cursor cursor, ViewGroup parent) {
          return inflater.inflate(R.layout.list_item, parent, false);
  
      }
  
  }
  </code></pre>
  
  <p>list_item.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingLeft="10dp"
  android:paddingRight="10dp"
  android:paddingBottom="5dp"
  android:clickable="true"
  android:descendantFocusability="beforeDescendants" &gt;
  
  &lt;RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="10dp"
      android:paddingTop="10dp"
      android:paddingBottom="10dp"
      android:paddingRight="10dp"
      android:background="@drawable/card_background_selector"
      android:descendantFocusability="afterDescendants"&gt;
  
  
          &lt;ImageView
              android:layout_marginRight="10dp"
              android:scaleType="fitXY"
              android:layout_width="100dp"
              android:layout_height="100dp"
              android:id="@+id/imageView" /&gt;
  
          &lt;TextView
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:textStyle="bold"
              android:id="@+id/tvName"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/name"
              android:layout_alignParentTop="true"
              android:layout_toRightOf="@+id/imageView"
              android:layout_toLeftOf="@+id/checkBox"/&gt;
  
          &lt;TextView
              android:textAppearance="?android:attr/textAppearanceMedium"
              android:textStyle="bold"
              android:id="@+id/tvPrice"
              android:textColor="@color/cadmium_orange"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/price"
              android:layout_below="@+id/tvDescription"
              android:layout_toRightOf="@+id/imageView" /&gt;
  
          &lt;TextView
              android:id="@+id/tvDescription"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/description"
              android:layout_below="@+id/tvName"
              android:layout_toRightOf="@+id/imageView" /&gt;
  
          &lt;LinearLayout
              android:id="@+id/quantity"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:layout_below="@+id/tvPrice"
              android:layout_toRightOf="@+id/imageView"
              android:layout_toEndOf="@+id/imageView" &gt;
  
              &lt;ImageButton
                  style="@style/My.Button"
                  android:id="@+id/ibSubtract"
                  android:layout_width="30dp"
                  android:layout_height="30dp"
                  android:src="@drawable/ic_remove_white_36dp"
                  android:padding="5dp" /&gt;
  
              &lt;EditText
                  android:background="#fff"
                  android:id="@+id/etQuantity"
                  android:layout_width="30dp"
                  android:layout_height="30dp"
                  android:focusable="false"
                  android:gravity="center"
                  android:inputType="number" /&gt;
  
              &lt;ImageButton
                  style="@style/My.Button"
                  android:id="@+id/ibAdd"
                  android:layout_width="30dp"
                  android:layout_height="30dp"
                  android:layout_marginRight="5dp"
                  android:src="@drawable/ic_add_white_36dp"
                  android:padding="5dp" /&gt;
  
  
          &lt;/LinearLayout&gt;
  
      &lt;CheckBox
          android:layout_alignParentRight="true"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/checkBox"
          android:checked="false" /&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>Any ideas? I would gladly appreciate any help. Thanks.</p>