【发布时间】:2019-07-18 09:56:36
【问题描述】:
我有一个名为 ArrayList<ArrayList<ImageButton>> boardImageButtons 的全局 2D ArrayList。
在方法onClick(View view) 中,我有一个名为((ImageButton) view) btn 的单击图像按钮。
我想获得该对象在 2D ArrayList 中的位置(i & j)。
我尽量避免运行 throw 所有 2D ArrayList,比较对象并获取 equals 对象的 i 和 j。
你有更好的建议吗?
有没有办法通过onClick(View view) 传递额外的变量?
【问题讨论】:
-
您可以创建一个
Map,将您的按钮标记到位置。类似Map<ImageButton, MyCustomXYPair>
标签: java android imagebutton