0

hi guys been making my app for about year now and ive never actually learned how to tidy up lol. i have lots of xml and java files and at the moment they are all in the standard folders. how can i move then in to separate folders so i have fragments in one folder, webviews in another and so on. because at the moment its a mess and im getting annoyed trying to find things.

every time i create a folder in android studio and try to move the file it makes the file i move fill with errors and any file associated with it.

as always thanks guys

Mark Harrop
  • 192
  • 1
  • 14

2 Answers2

2

You can place your Java files into packages. You can usually create a package by right-clicking the folder/package where you want the new folder to be, and click New -> Package. You can then move desired class to that new folder by drag and drop (Or create a new class in that folder and copy the previous one).

Unfortunately, you can't organize your XML files that way. A hack would be to name the files to order them in a certain way. For example, your layout for your activities may start with "act_", items for ListView by "items_", etc.

For the XML layouts, you can always declare in the gradle (if you're using one) the packages where you have saved the layouts.

sourceSets {
    main {
        res.srcDirs =
        [
                'src/main/res/layouts/layouts_category2',
                'src/main/res/layouts',
                'src/main/res'
        ]
    }
}

I point you to this answer for more information

Community
  • 1
  • 1
Sunshinator
  • 940
  • 11
  • 23
1

there's an option called refactor in android studio.
(i) make a new folder, say for example fragments.
(ii) go to that particular java file which u would like to move, e.g. TestFragment.java
(iii) right click on the above file (or fn + f6 if you're on a mac) to find a menu item called refactor, within it you'll find an option named move. Click on it.
(iv) Select you're destination package that is the folder you had created earlier and click on refactor. That is it :-).

niranjan_b
  • 132
  • 5