0

Ok, I have some fictional class

public class TEMP {
    String data;
    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (data != null) {

            }
        }
    };
}

And it looks like this in Android Studio: enter image description here

If I collapse all - it looks ugly:
enter image description here

If I remove that if block inside onClick() - it looks good:
enter image description here

Why is this happening and how can I solve this issue?

Goltsev Eugene
  • 3,325
  • 6
  • 25
  • 48
  • I have seen the same issue and it is annoying to me as well. I think we should either file a bug to Android Studio/Intellij IDEA , or to find the bug that most probably somebody else has already created. – dragi Jun 09 '16 at 18:48

1 Answers1

1

It's been a while, so I'm not sure how helpful this is.

This is folding the function into a lambda-like visual structure with Java 8 lambda-notation. Single method interfaces are (almost) equivalent to lambdas in Java 8. Android Studio currently does NOT support Java 8 lambda notation (details found at the bottom of this answer: Is it possible to use Java 8 for Android development?).

A workaround IS available for Java 8, based on the Jack toolchain. Here is the the workaround, and here is the deprecation of the Jack toolchain.

Another note is that according to here and here, Android Studio 2.4 preview 4 and later appears to support actual lambda notation. Note that these are previews, and the latest official version is 2.3.2.

As for how to fix it, I don't believe it is possible. You may be able to use the region feature to duplicate what you are trying to achieve. The link above is a how-to sort of thing.

AlterionX
  • 81
  • 1
  • 10
  • Hm, I forgot about this issue already;). Seems like in some later releases guys fixed that. In current version (2.3.2) I cannot reproduce that. – Goltsev Eugene Jun 01 '17 at 10:00
  • I'm still seeing the issue though. I have some rather large anonymous classes within my project that fold into a lambda expression instead of folding all the way in. I'm running 2.3.2 as well. – AlterionX Jun 01 '17 at 12:35