Dynamically creating Buttons and setting onClickListener

后端 未结 9 1001
囚心锁ツ
囚心锁ツ 2020-11-29 22:45

I have problem with handling dynamically created Buttons on Android. I\'m creating N buttons and I have to do the same method when button is clicked but I have to know which

9条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 23:13

    Is preferable not to mess up with the ids, setTag and getTag methods were designed for that purpose, it's the fast and clean way to set a bunch of button listeners on a dynamic layout

    This answer may you help: https://stackoverflow.com/a/5291891/2804001

提交回复
热议问题