简体   繁体   中英

2 Buttons in ListView in android

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.

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

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 l ike get & Set tag or get button view parent (which will be list row) as in this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM