0

How can I add get the reference of that textview while click the button in the list view row?

**---------------------------------

TextView Button

---------------------------------**

This is the example of my list view. I have used the View Holder concept to manipulate the listview dynamically. if i click the button, the value of textview want to change.

I had tried to change the value of the texview values while click the button, but the it updates the last row textview value for every button I click. thanks and regards.

Finally I got the answer following:

public void onClick(View v) {
    // TODO Auto-generated method stub

    LinearLayout layout=(LinearLayout) v.getParent();
    TextView text=(TextView)layout.findViewById(R.id.qcountHD);
    if (view.inc.getId() == v.getId()) {
        int count = Integer.parseInt(text.getText().toString());
        text.setText("" + (++count));
    } else if (view.dec.getId() == v.getId()) {
        int count = Integer.parseInt(text.getText().toString());
        if (!(count == 0)) {
            text.setText("" + (--count));
        }
    }
}

Thanks for the support.....

Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
Pravinkumar
  • 319
  • 1
  • 4
  • 15

1 Answers1

2

Finally I got the answer, we can get any of the child reference using the parent layout. It points the current parent and it's child's while You click the button.

public void onClick(View v) {
        // TODO Auto-generated method stub

    RelativeLayout layout=(RelativeLayout) v.getParent();
    TextView text=(TextView)layout.findViewById(R.id.qcountHD);
    TextView product=(TextView)layout.findViewById(R.id.productHD);
    TextView price=(TextView)layout.findViewById(R.id.priceHD);


    Log.d("Current Product ",product.getText().toString());
    Log.d("Current Price ",price.getText().toString());
    Log.d("Current Quantity ",text.getText().toString());

    if (view.inc.getId() == v.getId()) {
        int count = Integer.parseInt(text.getText().toString());
        text.setText("" + (++count));
    } else if (view.dec.getId() == v.getId()) {
        int count = Integer.parseInt(text.getText().toString());
        if (!(count == 0)) {
            text.setText("" + (--count));
        }
    }

}

Thank you....

Remees M Syde
  • 2,564
  • 1
  • 19
  • 42
Pravinkumar
  • 319
  • 1
  • 4
  • 15