所以我按以下方式设置鼠标侦听器:
int[] monsters = new int[12];
monsters[0] = MonsterSelector.BL_BLUE_BUFF;
monsters[1] = MonsterSelector.BL_RED_BUFF;
monsters[2] = MonsterSelector.BL_WOLVES;
monsters[3] = MonsterSelector.BL_WRAITHS;
monsters[4] = MonsterSelector.BL_GOLEMS;
monsters[5] = MonsterSelector.BARON;
monsters[6] = MonsterSelector.PU_BLUE_BUFF;
monsters[7] = MonsterSelector.PU_RED_BUFF;
monsters[8] = MonsterSelector.PU_WOLVES;
monsters[9] = MonsterSelector.PU_WRAITHS;
monsters[10] = MonsterSelector.PU_GOLEMS;
monsters[11] = MonsterSelector.DRAGON;
for(int monster = 1; monster < MonsterSelector.LAST+1; monster++){
final int currentMonster = monsters[monster-1];
ImageView iv = new ImageView(images.get(currentMonster), 50, 50);
ivs.put(currentMonster, iv);
ivs.get(currentMonster).addMouseListener(this);
}
我在班上有以下mouselistener实现:
@Override
public void mouseReleased(MouseEvent e) {
Component src = (Component) e.getSource();
Log.e(TAG, ""+src.getName());
}
现在问题是只有第一个mouselistener设置确实给出了输出。其余的只是忽略。我究竟做错了什么?我不能在多个对象上设置相同的mouselistener?
答案 0 :(得分:1)
我猜是MonsterSelector.LAST
未设置为应该的最高值。或者您初始化MonsterSelector.BL_BLUE_BUFF
,MonsterSelector.BL_RED_BUFF
等等都具有相同的int值?