我有以下代码:
private static boolean hasTargetStyle(AttributeSet attributes) {
final Enumeration<?> attributeNames = attributes.getAttributeNames();
while (attributeNames.hasMoreElements()) {
final Object attributeName = attributeNames.nextElement();
if (attributeName.equals(MY_STYLE_NAME)) {
return true;
}
}
return false;
}
现在我认为这段代码将遍历每个属性名称。但它只给我所有其他属性名称(具有偶数索引的属性名称)。
这里出了什么问题?
最佳答案
我认为它没有索引 - Set
没有索引。而且代码看起来不错。除非 getAttributeNames()
返回错误实现的枚举,否则它应该可以工作。
关于java - 遍历 AttributeSet 枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6125868/