0

I have the following java code:

message.setTag("_message");

where is run multiple times with different message assigned to it.

When I

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;
        }

    });

Only the first message gets highlight. How can I make all of the messages highlight?

Fane
  • 1,978
  • 8
  • 30
  • 58
  • What are you trying to do? – Athena Feb 15 '15 at 00:37
  • @Athena >Only the first message gets highlight. How can I make all of the messages highlight? – Fane Feb 15 '15 at 00:44
  • When you set `message.setTag("_message");`, add them to an ArrayList. In your onTouch(), traverse through the list and call `message.setBackgroundColor(Color.YELLOW);`. – Athena Feb 15 '15 at 00:48
  • @Athena Isn't it possible to get them into a temporary array in `findviewwithtag` and after go through the list? – Fane Feb 15 '15 at 00:49
  • No. Because `findViewWithTag()` will return the first instance in each case. And you will end up set the Background for the same View over and over. – Athena Feb 15 '15 at 00:58
  • @Athena hm, what would be the best way to highlight chat messages then?... Considering there might me many users involved, keeping a array log seems *expensive* and won't allow multi layouts too... – Fane Feb 15 '15 at 01:04
  • possible duplicate of [Find all views with tag?](http://stackoverflow.com/questions/5062264/find-all-views-with-tag) – StenSoft Feb 15 '15 at 01:23

0 Answers0