title: Increment/Decrements in a custom listview
body: <p>for a project of mine, i want to implement the kind of counter that this app uses (the white one, mine is the blue one). I have created the custom listview with the everything in place but for some reason, when i press either the + button or the - button, the increments do not work for that specific item. instead it increments items at either the bottom or other items that are not the one i pressed the button for. I have tried using switch cases and onClickMethod for the specific position in getView but it still just does not work. My question is how can i increment just for that specific item without it affecting others counts? I'm doing the increasing and decreasing of count in my getView method of my customAdapter class that extends baseAdapter. I feel like the problem is more logical and less code wise. Any help is appreciated. Thanks</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      final int pos = position;
      View myView = convertView;
  
      //if this is the first time coming here
      if(myInfater == null) {
          myInfater = (LayoutInflater) myActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      }
  
      if (myView == null) {
          myView = myInfater.inflate(R.layout.row_layout, null);
      }
  
  
  
      ImageView itemImage = (ImageView) myView.findViewById(R.id.itemImage);
      TextView itemName = (TextView) myView.findViewById(R.id.itemName);
      TextView itemPrice = (TextView) myView.findViewById(R.id.itemPrice);
  
      //stuff in linear layout
      itemCount = (TextView) myView.findViewById(R.id.itemCount);
      decreaseButton = (Button) myView.findViewById(R.id.itemDecrement);
      increaseButton = (Button) myView.findViewById(R.id.itemIncrement);
  
  
  
      final GroceryItem myItem = groceryItemList.get(position);
      myItem.setCount(myCount);
      myCount = myItem.getCount();
      globalPos = position; //gets the position so we can use it in onClick
  
      itemImage.setImageResource(myItem.getImageId());
      itemName.setText(myItem.getName());
      itemPrice.setText("$" + String.valueOf(myItem.getPrice()));
      itemCount.setText(String.valueOf(myCount));
  
  
      decreaseButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (myCount != 0) {
                  itemCount.setText(String.valueOf(myCount--));
                  System.out.println("decrease method count = " + myItem.getCount());
              }
          }
      });
  
      increaseButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              itemCount.setText(String.valueOf(myCount++));
              //myItem.setCount(getCount() + 1);
              System.out.println("count = " + myItem.getCount());
  
          }
      });
  
      return myView;
  }
  
  @Override
  public void onClick(View v) {
  
      System.out.println("My count is " + myCount); //for debugging
  
      switch (v.getId()) {
          //the - button was pressed
          case R.id.itemDecrement:
              if (myCount != 0) {
                  System.out.println("decrement button pressed"); //for debugging
                  myCount --; //decrement myCount
                  groceryItemList.get(globalPos).setCount(myCount);
                  itemCount.setText(String.valueOf(myCount)); //update the count
              }
              break;
          case R.id.itemIncrement:
              System.out.println("increment button pressed"); //for debugging
              myCount++; //increment myCount
              groceryItemList.get(globalPos).setCount(myCount);
              itemCount.setText(String.valueOf(myCount));
              break;
      }
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/bSJvg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bSJvg.jpg" alt="This is my program"></a> </p>
  
  <p><a href="https://i.stack.imgur.com/TblAr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TblAr.jpg" alt="enter image description here"></a></p>