在android中获取具有给定标记的所有元素

在android中获取具有给定标记的所有元素,android,Android,我有以下java代码: message.setTag("_message"); 其中,在为其分配不同消息的情况下多次运行 当我 message.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { View message = layout.findVi

我有以下java代码:

message.setTag("_message");
其中,在为其分配不同消息的情况下多次运行

当我

message.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            View message = layout.findViewWithTag("_message");

                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        message.setBackgroundColor(Color.YELLOW);
                        break;
                    case MotionEvent.ACTION_UP:
                        message.setBackgroundColor(0x00000000);
                        break;
                }


            return false;
        }

    });

只有第一条消息会突出显示。如何突出显示所有消息?

你想做什么?@Athena>只有第一条消息突出显示。如何突出显示所有消息?设置message.setTag_message;,将它们添加到ArrayList。在onTouch中,遍历列表并调用message.setBackgroundColorColor.YELLOW@Athena难道不可能将它们放入findviewwithtag中的一个临时数组中,然后遍历列表吗?不可能。因为findviewwithtag将在每种情况下返回第一个实例。最后,您将一遍又一遍地为同一视图设置背景。