1

I have set a couple of TextViews to call a method using the XML OnClick parameter. It works fine on a Lollipop device but it doesn't work on KitKat or older Android versions.

Why does it happen? Is there a way I can solve it without setting listeners for each view id?

TofferJ
  • 4,678
  • 1
  • 37
  • 49
Abaqus
  • 49
  • 1
  • 6

2 Answers2

3

Use android:clickable="true" in your textview.

In alternative, you can put your click logic in source code:

textView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
christian mini
  • 1,662
  • 20
  • 39
  • 2
    it worked correctly this is the correct answer for my problem, so the explanation is that the view needs to be android:clickable="true" in order to be compatible with android versions older than lollipop. – Abaqus Jul 26 '17 at 19:17
  • It seems like onClick does set the clickable attribute in Android 5.0 Lollipop (API 21). – christian mini Jul 26 '17 at 19:25
  • LOL I'm very happy to have found this answer.. but... what the hell is the reasoning behind this?? should it be called clickableOnAPI19orLess. ?? – Nerdy Bunz May 15 '18 at 06:06
0

Without any code I have to assume that, since you're talking about challenges with pre-lollipop devices, you're having trouble with elevation values.

Check out this link: Add elevation/shadow on toolbar for pre-lollipop devices

anomeric
  • 688
  • 5
  • 17