title: How to increment and decrement value of textview in listview?
body: <p>I have made a listview with the following items on each row</p>
  
  <ol>
  <li>Image Icon.</li>
  <li>Button.</li>
  <li>TextView</li>
  <li>Button.</li>
  <li>TextView.</li>
  </ol>
  
  <p>The 3rd textview is between two buttons(button will increase and decrease the value shown in the textview).when I am increasing and decreasing the value of textview of first row and then I go to second row it is taking the previous value when I increase and decrease its value.
  I am using a counter and incrementing the counter by fixed amount on click of button.</p>
  
  <p>Issue Faced:</p>
  
  <ol>
  <li>I am initializing counter but as there many rows in the listview its taking the previous value as initial value for second row.How to refresh the counter value?</li>
  <li>How to restore the initial value of textview to its original value?</li>
  </ol>
  
  <p>I have used adapter class.</p>
  
  <p>How to resolve this issue as I am new to android.
  Tell me way to do this.</p>
  
  <p>This is my adapter class:</p>
  
  <pre><code>public class CartListViewAdapter extends BaseAdapter{
      private Context mcontext;
      private static int counter;
      private String stringVal;
      //private static int i = position;
  
      public CartListViewAdapter(Context c){
          mcontext = c;
  
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return mThumbIds.length ;
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
  
  
          View myView = convertView;
  
          //if (convertView == null) {  // if it's not recycled, initialize some attributes
          //Inflate the layout
  
          LayoutInflater inflater = (LayoutInflater)mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);           
          myView = inflater.inflate(R.layout.row, null);
  
  
          // Add The Image!!!           
          ImageView iv = (ImageView)myView.findViewById(R.id.image);
          iv.setImageResource(mThumbIds[position]);
  
  
          // Add The Text!!!
          TextView tv = (TextView)myView.findViewById(R.id.text);
          tv.setText(names[position] );
  
          final TextView tv1 = (TextView)myView.findViewById(R.id.text1);
          tv1.setText(names1[position]);
  
          TextView tv3 = (TextView)myView.findViewById(R.id.text3);
          tv3.setText(names3[position]);
  
  
  
          ImageButton button = (ImageButton)myView.findViewById(R.id.addbutton);
          button.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
  
  
                  //Toast.makeText(mcontext,"Button is clicked",Toast.LENGTH_SHORT).show();
  
                  //              counter+=250;
                  //              stringVal = Integer.toString(counter);
                  //              tv1.setText(stringVal);
  
                  for(int position=0;position&lt;mThumbIds.length;position++){
  
  
                      counter = 250;
                      counter+=250;
                      stringVal = Integer.toString(counter);
                      tv1.setText(stringVal);
                  }
  
              }
          });
  
  
  
          ImageButton button2= (ImageButton)myView.findViewById(R.id.subbutton);
          button2.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
  
  
                  //Toast.makeText(mcontext,"Button is clicked",Toast.LENGTH_SHORT).show();
                  for(int position=0;position&lt;mThumbIds.length;position++){
  
  
                      counter = 250;
                      counter-=250;
                      stringVal = Integer.toString(counter);
                      tv1.setText(stringVal);
  
  
                  }
  
              }
          });
  
  
  
          return myView;
      }
  
  
  
  
      private Integer[] mThumbIds = {
  
              R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher
      };
  
      private String[] names={"ab","cd","ef"};
  
      private String[] names1 = {"250","250","250"};
  
      private String[] names3 = {"yhhjd","hnbnn","fdffd"};
  
  
  }
  </code></pre>
  
  <p>This is my xml:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_gravity="center_horizontal"
      android:orientation="horizontal" &gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="left"
          android:orientation="vertical"
          android:padding="10sp" &gt;
  
          &lt;ImageView
              android:id="@+id/image"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:src="@drawable/ic_launcher" /&gt;
  
          &lt;TextView
              android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="10sp" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;ImageButton
          android:id="@+id/addbutton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="50sp"
          android:layout_marginTop="20sp"
          android:background="@android:color/background_light"
          android:src="@android:drawable/ic_input_add" /&gt;
  
      &lt;TextView
          android:id="@+id/text1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="3sp"
          android:layout_marginTop="20sp" /&gt;
  
      &lt;ImageButton
          android:id="@+id/subbutton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="20sp"
          android:background="@android:color/background_light"
          android:src="@android:drawable/ic_input_add" /&gt;
  
      &lt;TextView
          android:id="@+id/text3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginRight="10sp"
          android:layout_marginTop="20sp"
          android:layout_weight="0.3"
          android:gravity="right" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Thanks.</p>