title: Android Plus & Minus buttons clicked value display in multiple rows not working correctly in Listview
body: <p>I'm a beginner in android development.I have two buttons and TextView in a linear layout. When i click plus button value increase for multiple row items and same for minus button clicking time.Also when I scrolling clicked value move to next position.Can you please help me how to fix the bugs.Below i wrote i my code.<a href="https://i.stack.imgur.com/wk48h.jpg" rel="nofollow noreferrer">Listview item image.</a></p>
  <p>ListViewAdapter.java</p>
  <pre><code>public class ItemListAdapter extends BaseAdapter {
  public Context context;
  public LayoutInflater inflater;
  public ArrayList&lt;JSONObject&gt; al = null;
  
  public ItemListAdapter(Activity context, ArrayList&lt;JSONObject&gt; itemListAl) {
  
      // TODO Auto-generated constructor stub
      super();
      this.context = context;
      this.al = itemListAl;
      
      this.inflater = (LayoutInflater) context
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return al.size();
  }
  
  @Override
  public Object getItem(int position) {
      // TODO Auto-generated method stub
      return al.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
  }
  
  
  
  
  class ViewHolder {
      TextView txtListItems;
      ImageView imgArrow;
      TextView qtyview;
      TextView qtyvalue;
      ImageButton increment;
      ImageButton decrement;
  
  
      RelativeLayout rootLayout;
  
  
  }
  
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      int type = getItemViewType(position);
  
      System.out.println(&quot;getView &quot; + position + &quot; &quot; + convertView + &quot; type = &quot; + type);
      final ViewHolder holder;
      if (convertView == null) {
          //LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          //row = inflater.inflate(R.layout.items_rowview_plus, parent, false);
  
          convertView = inflater.inflate(R.layout.items_rowview_plus,parent, false);
          holder = new ViewHolder();
          holder.txtListItems = (TextView) convertView.findViewById(R.id.tv_listItems);
          holder.imgArrow = (ImageView) convertView.findViewById(R.id.img_arrow);
          holder.qtyview = (TextView) convertView.findViewById(R.id.qty_view);
          holder.qtyvalue = (TextView) convertView.findViewById(R.id.qty_value);
          holder.increment = (ImageButton) convertView.findViewById(R.id.increment_btn);
          holder.decrement = (ImageButton) convertView.findViewById(R.id.decrement_btn);
          holder.rootLayout = (RelativeLayout) convertView
                  .findViewById(R.id.root_RelativeLayout);
          holder.increment.setTag(holder);
          holder.decrement.setTag(holder);
          convertView.setTag(holder);
  
      }
     else {
       holder = (ViewHolder) convertView.getTag();
      }
  
      try {
          if(position==0){
              //convertView.setBackgroundResource(R.drawable.listview_top);
              convertView.setBackgroundResource(R.drawable.listview_header);
  
          }
          else if(position==al.size()-1){
              convertView.setBackgroundResource(R.drawable.listview_bottom);
          }
  
          else{
              convertView.setBackgroundResource(R.drawable.listview_middle);
          }
      
          if(position == 0){
              
              holder.txtListItems.setText(al.get(position).get(&quot;ListviewHeader&quot;).toString());
              holder.imgArrow.setVisibility(View.GONE);
              holder.qtyvalue.setVisibility(View.GONE);
              holder.qtyview.setVisibility(View.GONE);
              holder.increment.setVisibility(View.GONE);
              holder.decrement.setVisibility(View.GONE);
              //convertView.setBackgroundResource(R.drawable.listview_top);
              holder.txtListItems.setEnabled(false);
              holder.txtListItems.setTextColor(context.getResources().getColor(R.color.white));
              //holder.rootLayout.setBackgroundResource(R.color.dark_blue);
              
          }
  
          else{
          holder.txtListItems.setText(al.get(position).get(&quot;c_field_name&quot;).toString());
          holder.imgArrow.setVisibility(View.VISIBLE);
              holder.qtyvalue.setVisibility(View.VISIBLE);
              holder.qtyview.setVisibility(View.VISIBLE);
              holder.increment.setVisibility(View.VISIBLE);
              holder.decrement.setVisibility(View.VISIBLE);
          holder.txtListItems.setEnabled(true);
  
          holder.txtListItems.setTextColor(context.getResources().getColor(R.color.Black));
          
          }
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      
      holder.rootLayout.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              if (!al.get(position).isNull(&quot;c_field_name&quot;)) {
              Intent intent = new Intent(v.getContext(), ItemDetailsActivity.class);
                              
              try {
  
  
                  SharedData.sharedInstance().editItemDetails=false;
                  SharedData.sharedInstance().ListId = al.get(position).getString(&quot;c_id&quot;).toString();
                  Log.v(&quot;cid&quot;,SharedData.sharedInstance().ListId);
                  SharedData.sharedInstance().ListName = al.get(position).get(&quot;c_field_name&quot;).toString();
                  Log.v(&quot;ListName&quot;,SharedData.sharedInstance().ListName);
                  SharedData.sharedInstance().CubicValue = al.get(position).get(&quot;c_cubic_feet&quot;).toString();
                  Log.v(&quot;CubicValue&quot;,SharedData.sharedInstance().CubicValue);
                  SharedData.sharedInstance().strListName = &quot;ListItemView&quot;;
  
  
  
                  
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              v.getContext().startActivity(intent);
  
  
              }
          }
      });
  
      
      holder.increment.setOnClickListener(new View.OnClickListener() {
          int count=0;
          @Override
          public void onClick(View v) {
  
              count = Integer.valueOf(holder.qtyvalue.getText().toString());
              count = count+1;
              holder.qtyvalue.setText(String.valueOf(count));
              Log.d(&quot;Plus Btn&quot;, &quot;Clicked&quot;);
          }
      });
      holder.decrement.setOnClickListener(new View.OnClickListener() {
          int count=0;
          @Override
          public void onClick(View v) {
  
              count = Integer.valueOf(holder.qtyvalue.getText().toString());
              count = count-1;
              holder.qtyvalue.setText(String.valueOf(count));
  
  
          }
      });
  
      return convertView;
  }
  </code></pre>
  <p>}</p>
  <p>item_rowview_plus.xml</p>
  <pre><code>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:id=&quot;@+id/root_RelativeLayout&quot;
  android:layout_width=&quot;fill_parent&quot;
  android:layout_height=&quot;wrap_content&quot;
  android:background=&quot;#E6E6E6&quot; &gt;
  
  
  
  &lt;LinearLayout
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;45dp&quot;
      android:orientation=&quot;horizontal&quot;
      android:layout_alignParentTop=&quot;true&quot;
      android:layout_alignParentLeft=&quot;true&quot;
      android:layout_alignParentStart=&quot;true&quot;&gt;
  
      &lt;TextView
          android:id=&quot;@+id/tv_listItems&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;44dp&quot;
          android:layout_alignParentLeft=&quot;true&quot;
          android:layout_marginLeft=&quot;10dp&quot;
          android:layout_weight=&quot;0.15&quot;
          android:gravity=&quot;top&quot;
          android:padding=&quot;5dp&quot;
          android:text=&quot;TextView&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/qty_view&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;38dp&quot;
          android:layout_alignBottom=&quot;@+id/decrement_btn&quot;
          android:layout_weight=&quot;0.02&quot;
          android:text=&quot;Qty&quot;
  
  
          /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/qty_value&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_weight=&quot;0.02&quot;
          android:text=&quot;0&quot;
          android:textAlignment=&quot;center&quot;
          android:textStyle=&quot;bold&quot; /&gt;
  
      &lt;ImageButton
          android:id=&quot;@+id/increment_btn&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;match_parent&quot;
          android:layout_gravity=&quot;top&quot;
          android:background=&quot;@drawable/button_plus_normal&quot; /&gt;
  
      &lt;ImageButton
          android:id=&quot;@+id/decrement_btn&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;match_parent&quot;
          android:background=&quot;@drawable/button_minus_normal&quot;
          android:layout_gravity=&quot;top&quot;
          android:cropToPadding=&quot;true&quot; /&gt;
  
      &lt;ImageView
          android:id=&quot;@+id/img_arrow&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_alignParentRight=&quot;true&quot;
          android:layout_centerVertical=&quot;true&quot;
          android:layout_marginRight=&quot;5dp&quot;
          android:layout_marginTop = &quot;23dp&quot;
          android:background=&quot;@drawable/common_listview_arrow_right&quot;
          /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Can you please tell how to fix the bugs.</p>