【发布时间】:2012-04-21 15:31:10
【问题描述】:
无论如何要为JButton 设置一个ID。我在 Android 中已经习惯了。
我正在寻找类似以下的内容:
newButton.setId(objectcounter);
【问题讨论】:
-
“我在 Android 中已经习惯了。” 在 Android 中的处理方式可能与在 J2SE 中不同。习惯于像语言通常那样做。在罗马时..
无论如何要为JButton 设置一个ID。我在 Android 中已经习惯了。
我正在寻找类似以下的内容:
newButton.setId(objectcounter);
【问题讨论】:
您可以使用一个属性名称:
newButton.setName(String.valueOf(objectCounter))
或者,您可以使用 clientProperties 来存储任意值:
newButton.putClientProperty("id", Integer.valueOf(objectCounter))
要从客户端属性映射中获取值,您需要这样的东西。
Object property = newButton.getClientProperty("id");
if (property instanceof Integer) {
int objectCounter = ((Integer)property);
// do stuff
}
【讨论】:
String 或Map.Entry<Object, Object> 的任何内容。