title: to increase and decrease value inside textview on button click on particular position
body: <p>I want to increment and decrement values inside textview on click of button at particular position.I have made custom listview.Problem is that when i click on + button of first item, qty increase by 1 and prize increases by 20 but when i click on second item the quantity increases directly from 0 to 2  and prize increases directly to 40.I want Book must get increased by 20,pen must get increased by 30 and pencil by 5 and same is for decrement.As I am new in android plz help me.Thanks for your help in advance.Following is my code:-</p>
  
  <pre><code>order.xml
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent" android:layout_height="match_parent"&gt;
  
      &lt;LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/item_name"
         android:orientation="horizontal"
         android:layout_toRightOf="@+id/sr_no"
  
         &gt;
         &lt;TextView
             android:layout_width="150dp"
             android:layout_height="50dp"
             android:layout_toRightOf="@+id/srno"
             android:layout_below="@+id/breakfast"
             android:text="ITEM NAME"
             android:id="@+id/itemname"
             android:gravity="center"
             android:textStyle="bold"
             android:textColor="#000"
             /&gt;
  
     &lt;/LinearLayout&gt;
     &lt;LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/qtity"
         android:orientation="horizontal"
         android:layout_toRightOf="@+id/item_name"
  
         &gt;
         &lt;TextView
             android:layout_width="40dp"
             android:layout_height="50dp"
             android:layout_toRightOf="@+id/itemname"
             android:layout_below="@+id/lunch"
             android:text="QTY"
             android:id="@+id/quantity"
             android:gravity="center"
             android:textStyle="bold"
             android:textColor="#000"
             /&gt;
  
     &lt;/LinearLayout&gt;
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:id="@+id/count"
          android:layout_toRightOf="@+id/qtity"
  
          &gt;
          &lt;TextView
              android:layout_width="50dp"
              android:layout_height="50dp" /&gt;
  
      &lt;/LinearLayout&gt;
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/rate"
          android:orientation="horizontal"
          android:layout_toRightOf="@+id/count"
  
          &gt;
          &lt;TextView
              android:layout_width="50dp"
              android:layout_height="50dp"
              android:layout_toRightOf="@+id/quantity"
              android:layout_below="@+id/snacks"
              android:text="PRICE"
              android:id="@+id/price"
              android:gravity="center"
              android:textStyle="bold"
              android:textColor="#000"
              /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/sr_no"
          android:orientation="horizontal"
  
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"&gt;
          &lt;TextView
              android:layout_width="50dp"
              android:layout_height="50dp"
              android:layout_below="@+id/breakfast"
              android:layout_margin="2dp"
              android:layout_marginTop="10dp"
              android:text="SR.NO"
              android:gravity="center"
              android:textStyle="bold"
              android:textColor="#000"
              android:id="@+id/srno"
              /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;ListView
          android:layout_width="match_parent"
          android:layout_height="350dp"
          android:id="@+id/listdetails"
          android:scrollbars="vertical"
          android:scrollbarStyle="insideOverlay"
          android:layout_below="@+id/item_name"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true"&gt;
  
  
      &lt;/ListView&gt;
  
  
  &lt;/RelativeLayout&gt;
  
  
  customlist.xml
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent" android:layout_height="match_parent"&gt;
  
      &lt;TextView
          android:layout_width="50dp"
          android:layout_height="50dp"
          android:id="@+id/s_no"
          android:layout_marginTop="5dp"
          android:gravity="center"
          android:textColor="#000"
          android:textStyle="bold"
          /&gt;
      &lt;TextView
          android:layout_width="150dp"
          android:layout_height="50dp"
          android:gravity="center"
          android:textColor="#000"
          android:textStyle="bold"
          android:id="@+id/i_name"
          android:layout_marginTop="5dp"
          android:layout_toRightOf="@+id/s_no"
          /&gt;
      &lt;TextView
          android:layout_width="50dp"
          android:layout_height="50dp"
          android:id="@+id/qty"
          android:layout_toRightOf="@id/i_name"
          android:gravity="center"
          android:textColor="#000"
          android:textStyle="bold"
          android:layout_marginTop="5dp"
          /&gt;
      &lt;Button
          android:layout_width="25dp"
          android:layout_height="25dp"
          android:id="@+id/pl"
          android:layout_marginTop="5dp"
          android:layout_toRightOf="@+id/qty"
          android:background="@drawable/plus1"
          /&gt;
      &lt;Button
          android:layout_width="25dp"
          android:layout_height="25dp"
          android:id="@+id/min"
          android:layout_marginTop="3dp"
          android:layout_below="@id/pl"
          android:layout_toRightOf="@id/qty"
          android:background="@drawable/minus1"
          /&gt;
  
      &lt;TextView
          android:layout_width="60dp"
          android:layout_height="50dp"
          android:id="@+id/pr"
          android:gravity="center"
          android:textColor="#000"
          android:textStyle="bold"
          android:layout_marginLeft="10dp"
          android:layout_alignBottom="@+id/min"
          android:layout_toRightOf="@+id/pl"
          android:layout_toEndOf="@+id/pl" /&gt;
  &lt;/RelativeLayout&gt;
  
  
  Order.java
  public class Order extends Activity {
  
      ListView list_item;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.order);
  
          list_item=(ListView)findViewById(R.id.listdetails);
  
          int sr[]={1,2,3};
         // int sr=1;
        //  String[] item_name={"book","pen","notebook","pendrive","rubber","scale","pencil","slate","crayons","compass box"};
          String [] itemname={"book","pen","pencil"};
          int [] quantity={0,0,0};
          //int[] price={20,20,25,25,30,30,20,10,25,10};
          int [] price={20,30,5};
  
  
  
              Custom_Adapter ca=new Custom_Adapter(this,sr,itemname,price,quantity);
              list_item.setAdapter(ca);
      }
  }
  
  
  CustomAdapter.java
  public class Custom_Adapter extends BaseAdapter {
      Activity a;
     int sr [];
  int quantity[];
  
      String itemname[];
      int price[];
  
      TextView qt;
      public static int count=0,count2=0,cal;
  
  
      private String data,pricedata;
  
  
  
      public Custom_Adapter(Activity a, int[] sr, String[] itemname, int[] price, int quantity[]) {
          this.a = a;
          this.sr = sr;
          this.itemname = itemname;
          this.price = price;
          this.quantity = quantity;
  
      }
  
      @Override
      public int getCount() {
          return itemname.length;
      }
  
      @Override
      public Object getItem(int position) {
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
      public class viewHolder{
  
          TextView srh,item,qt,rate;
          Button plus,minus;
      }
  
      @NonNull
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
          final viewHolder viewHolder=new viewHolder();
          LayoutInflater li=a.getLayoutInflater();
          View view=li.inflate(R.layout.customlist,parent,false);
          viewHolder.srh=(TextView)view.findViewById(R.id.s_no);
          viewHolder.item=(TextView)view.findViewById(R.id.i_name);
          viewHolder.qt=(TextView)view.findViewById(R.id.qty);
          viewHolder.plus=(Button)view.findViewById(R.id.pl);
          viewHolder.minus=(Button)view.findViewById(R.id.min);
          viewHolder.rate=(TextView)view.findViewById(R.id.pr);
  
  
  
  
          viewHolder.srh.setText(Integer.toString(sr[position]));
          viewHolder.item.setText(itemname[position]);
          viewHolder.qt.setText(Integer.toString(quantity[position]));
  
          viewHolder.rate.setText(Integer.toString(price[position]));
  
  
  
  
  
          viewHolder.plus.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                     count+=1;
                  count2+=20;
                  viewHolder.qt.setText(String.valueOf(count));
                  viewHolder.rate.setText(String.valueOf(count2));
  
  
  
              }
          });
          viewHolder.minus.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
  
                  if (count&gt;0 &amp;&amp; count2&gt;0) {
                      count = count - 1;
                      count2-=20;
                      viewHolder.qt.setText(String.valueOf(count));
                      viewHolder.rate.setText(String.valueOf(count2));
                  }
  
              }
          });
  
          return view;
      }
  }
  </code></pre>