Android: ListView elements with multiple clickable buttons

后端 未结 8 1193
天命终不由人
天命终不由人 2020-11-22 01:58

I\'ve a ListView where every element in the list contains a TextView and two different Buttons. Something like this:

ListView
------------------         


        
8条回答
  •  误落风尘
    2020-11-22 02:16

    The solution to this is actually easier than I thought. You can simply add in your custom adapter's getView() method a setOnClickListener() for the buttons you're using.

    Any data associated with the button has to be added with myButton.setTag() in the getView() and can be accessed in the onClickListener via view.getTag()

    I posted a detailed solution on my blog as a tutorial.

提交回复
热议问题