How to rearrange code with overridden methods at the top in Android Studio?
Asked Answered
C

1

13

In the Preferences > Code Style > Arrangement- tab, I have to manually enter matching rules for specific method names if I want to arrange them to be at the top.

For example, I have an activity where I want the lifecycle- and other overridden methods to be at the top:

public final class MyActivity extends Activity {
    // Fields

    @Override
    public final void onCreate(...) { ... }
    ...

    // Other methods
}

Is there a better way?

Chrismatory answered 25/4, 2014 at 7:9 Comment(0)
H
7

In Android Studio 3.0 under Preferences > Editor > Code Style > Java > Arrangement Tab you can add a rule to match overridden and place it after the rules for fields and constructors but before the rules for methods.

You can then perform Code > Rearrange Code and it should arrange your code appropriately

Arrangement Screenshot

Halfon answered 21/9, 2017 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.