title: How to select a textview having an id from a custom listview in android?
body: <p>I have a custom listview having the following layout:
  <img src="https://i.stack.imgur.com/iNntE.jpg" alt="GUI view of the layout"></p>
  
  <p>I have defined an onClick method for 'qadd' button and 'qsub' button in xml using <code>android:onClick</code> property.</p>
  
  <p>In my Activity class how do I select the 'quantity' textView for current position?</p>
  
  <p>I tried this but it only updates 'quantity' textView at first position.</p>
  
  <pre><code>public void addClicked(View v) {
          final int position = list.getPositionForView((View) v.getParent().getParent());
          long rec_id = adapter.getItemId(position);
  
          JSONObject o = (JSONObject) fullList.get(rec_id + "");
  
          TextView q = (TextView)findViewById(R.id.quantity);
  
          int quantity = Integer.parseInt((String) q.getText());
  
          quantity++;
  
          q.setText(quantity + "");
  
          try {
  
              String price = o.getString("price");
              subtotal = subtotal + (Integer.parseInt(price) * quantity);
              total_text = (TextView) findViewById(R.id.subtotal);
              total_text.setText(subtotal + "");
  
              // Log.d("position", price);
  
          } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>The above code goes wrong at this line:</p>
  
  <pre><code>TextView q = (TextView)findViewById(R.id.quantity);
  </code></pre>
  
  <p>It always selects the textView at first position.
  Please ask if any other piece of code is needed.</p>
  
  <p>Entire custom_list_layout.xml is as follows:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/list_selector"
      android:orientation="horizontal"
      android:padding="5dip" &gt;
  
  
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentRight="true"
          android:layout_below="@+id/checkBox1" &gt;
  
          &lt;LinearLayout
              android:id="@+id/thumbnail"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginRight="5dip"
              android:background="@drawable/image_bg"
              android:padding="3dip" &gt;
  
              &lt;ImageView
                  android:id="@+id/item_img"
                  android:layout_width="50dip"
                  android:layout_height="50dip"
                  android:src="@drawable/ic_launcher" /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_weight="2.5"
              android:orientation="vertical" &gt;
  
              &lt;TextView
                  android:id="@+id/item_name"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Item name"
                  android:textColor="#040404"
                  android:textSize="15dip"
                  android:textStyle="bold"
                  android:typeface="sans" /&gt;
  
              &lt;TextView
                  android:id="@+id/item_desc"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:text="Item description"
                  android:textColor="#343434"
                  android:textSize="10dip" /&gt;
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_weight="0.75"
              android:gravity="right"
              android:orientation="vertical" &gt;
  
              &lt;LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:gravity="right"
                  android:orientation="horizontal" &gt;
  
                  &lt;TextView
                      android:id="@+id/rupee"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:gravity="right"
                      android:text="Rs. "
                      android:textColor="#EC1669"
                      android:textSize="10dip"
                      android:textStyle="bold" /&gt;
  
                  &lt;TextView
                      android:id="@+id/item_price"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_marginRight="5dip"
                      android:gravity="right"
                      android:text="0 "
                      android:textColor="#EC1669"
                      android:textSize="10dip"
                      android:textStyle="bold" /&gt;
  
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:gravity="bottom|right" &gt;
  
                  &lt;Button
                      android:id="@+id/qadd"
                      style="?android:attr/buttonStyleSmall"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:minHeight="24dp"
                      android:minWidth="24dp"
                      android:onClick="addClicked"
                      android:text="+" /&gt;
  
                  &lt;TextView
                      android:id="@+id/quantity"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="0"
                      android:textAppearance="?android:attr/textAppearanceSmall" /&gt;
  
                  &lt;Button
                      android:id="@+id/qsub"
                      style="?android:attr/buttonStyleSmall"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:minHeight="24dp"
                      android:minWidth="24dp"
                      android:onClick="subClicked"
                      android:text="-" /&gt;
  
              &lt;/LinearLayout&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><a href="http://www.mediafire.com/download/h3qnoocr3p8mn7i/myMenu.zip" rel="nofollow noreferrer">Link to my entire project.</a></p>