-2

After coming back to my project I noticed that the set.onclicklisteners had been shortened until clicked on, then it shows full code, just wondering if there is a quick way to do this as it could be quite handy to organize my code.

Example:

alongtimeBtn.setOnClickListener(new View.OnClickListener()

    {

        public void onClick(View v) {
            alongtimeagomp.start();
        }
    });

was shortened to

enter image description here

I put this question into google and was shown how to hide code completely using ProGuard which is not what I'm looking for.

Krupa Kakkad
  • 857
  • 1
  • 13
  • 28
liam
  • 9
  • 2
  • 3
  • Possible duplicate of [Android Studio Collapse definitions and methods](https://stackoverflow.com/questions/18445044/android-studio-collapse-definitions-and-methods) – BakaWaii Aug 30 '17 at 11:41

4 Answers4

7

FYI, why your method is being shortened by Android Studio is because it's actually a lambda expression.

Apart from the shortcuts mentioned in other answers, there's also one weird trick you won't believe to neatly fold your code where you need it. You can define your custom regions of code, like so:

//region REGION NAME

someMethod();

someOtherMethod();

//endregion

Region name is of course totally up to you. After you define a region, IDE will be showing something like this:

enter image description here

where "Parsing JSON" is region name, and the green color denotes the region area. You can click "+" to expand it and "-" to collapse.

lidkxx
  • 2,731
  • 2
  • 25
  • 44
5

You can simple use CTRL + SHFT + '-' for minimizing all the code CTRL + SHFT + '+' for expanding all the code in android studio

MRX
  • 1,400
  • 3
  • 12
  • 32
1

you can also use Ctrl + > for minimizing and ctrl + > to for expanding

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

Select code and press CTRL+> for hide and press again to show I hope it helps you

Vijay Chaudhary
  • 228
  • 2
  • 12