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?

1
  • can you add you java and xml code? I have an sugestion but i need to see the code Jul 26, 2017 at 18:56

2 Answers 2

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

        }
    });
3
  • 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, 2017 at 19:17
  • It seems like onClick does set the clickable attribute in Android 5.0 Lollipop (API 21). Jul 26, 2017 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. ?? May 15, 2018 at 6: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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.