1

I have a custom ListView in which there are 2 buttons and a textview in each row.

I want to change the text of the clicked button. How to identify that which button of which row has been clicked and then how to change the text of the same button.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vipul J
  • 6,641
  • 9
  • 46
  • 61
  • Sample code will be a great help..!! – Vipul J Jun 29 '12 at 18:11
  • 1
    in getView method of adapter you can define button click event and from there you can all your task | depend on your requirement – rajpara Jun 29 '12 at 18:13
  • Thanks for reply..!! I did the same but after doing so the difined action is performed on the last button only even if I click 1st button. – Vipul J Jun 29 '12 at 18:20

2 Answers2

1
How to identify that which button of which row has been clicked

Use onClickListener(). When a button is clicked that button's onClickListener will be called.

How to change the text of the same button

In onClickListener() you can do something like

yourTextView.setTextColor(Color.rgb(0,0,0)); //replace 0,0,0 with the rgb value of the color
Manto
  • 1,069
  • 2
  • 15
  • 34
  • after onClickListener(), the defined action is performed on the last button only even if I click 1st button. How to do it for exactly clicked button, like if I press the button of 2nd row, how to identify that button of secon row has been clicked out of 10 rows..? – Vipul J Jun 29 '12 at 18:23
  • you can identify them by the id of the buttons. b1 = buttons. findViewBy(R.id.Button1) – Manto Jun 29 '12 at 18:31
  • How to identify which button has been clicked..? – Vipul J Jun 29 '12 at 18:37
  • in the onClick(View v) function, you can call v.getId() on the incoming view. if that is equal to R.id.button1.. it was button1. then you can call button1.setText() or whatever you need to do with that button. – Joel Jun 29 '12 at 20:09
0

there are lots of example for the having Different Clickable Views in one single ListView

like this

point should keep

You need set the listener to each view in getView (don't create in each time in get view just pass already created one or can pass this and implement the listener in same adapter class)

You 'll also required the row position so can use different logic like get & Set tag or get button view parent (which will be list row) as in this link

Community
  • 1
  • 1
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36