If you ever worked with Xcode then you must know the power of “#pragma mark” macro. You could just define regions of code using that and sometimes it helps when you have classes that can get a bit big or if you just want to have a nice structure of your class.
Well you can do that on Android Studio or IntelliJ IDEA or any of JetBrains’s IDE.
Using the steps below you can group your code and name the group however you like and also contract/expand the groups of code.
1. Open the IDE you are using
2. Select the code you want to group like in the image below
3. Press Ctrl + Alt + T and select the “region .. end region comments”
4. Now the code is surrounded with “//region” / “//endregion” lines, you can see that the region can be fold-able
5. You can now edit the description of your group
6. You can easily see the code within your group without having to expand the group, just hover the group description with the mouse pointer
As you can see from the first and last images, the class body is reduced dramatically and it can be better organised.
See more about this here.
Search In Blog
Want to donate?
Recent Posts: My Android Solutions
If you ever wondered how to read and parse a simple JSON file stored in the assets directory of your Android project, here is a way to do it.
In this tutorial I will create a simple Sectioned RecyclerView that will show 2 sections and a few items in each section and how to move an item from one section to another. Note: For RecyclerView I used AndroidX imports and not android.support.v7.widget.RecyclerView! Setup We need to import the recycler view from AndroidX. The build.gradle…
Recently, I had to add a perfect square CardView and I wanted to achieve this without hardcoding its width and height. I happily discovered the power of ConstraintLayout and this is how I managed to create a perfect square which should work on every dimension. In my project I created a RecyclerView with 2 columns,…