I have an app on the iPhone and need to port it to android. For this I would like to group screen related files like classes and xml per screen in one "screen group" per screen somehow, ideally also strings and other value files
if I use folders I can only group res files separately and src files separately.
what would be the best way?
Thanks very much!
EDIT:
If that should not be possible, how to best then solve this issue? Do you create a subfolder in the src and another in the res for each screen?
The way you group files for the iphone is not possible for an android project. Android has pre determined folders which hold specific files, if you break this structure, your building process will fail. Its not ideal but that just how it it.
When it comes to source java files, they follow the concept of packages which are basically folders. The 'src' folder is the part where you can create sub folders as you desire. If you are adamant about keeping the files related to a screen in one place, you should create the layouts with java code and not use layout xml files.
But using xml layout files make development much easier and faster. Consider that as the presentation and java files as the logic+data. So group java files as you want and leave xml files in the layout folder with easy to identify names.
android uses certain directory layout for project structures (i.e. convention over configuration). Basically you will want to put your XML layout files in res/layout directory. Please read http://developer.android.com/guide/developing/projects/index.html#ApplicationProjects for further information.
Unfortunately, there's no easy way to do this in Eclipse. You can't create custom directories in your Android app's /res directory, you can only use permitted dir-names. E.g. you can't have a /res/layout-myscreen1 and /res/layout-myscreen2. You also must put your resources in /res, and your code files in packages, so they're at separate places in your project.
You can use Working Sets to group related files together however, but they're quite painful to use IMHO. Check the eclipse docs and tutorials out on them.
Related
When building a hybrid Xamarin Android app, we have a bizarre, intermittent issue.
The app is quite large and split into several components.
App1
App1.Android
App1.iOS
App2
App2.Android
App2.iOS
Shared.Core
Shared.Android
Shared.iOS
App1.Android and App2.Android share Shared.Core and Shared.Android, App1.iOS and App2.iOS shared Shared.Core and Shared.iOS. It's Shared.Android (an Xamarin Android library) which is vexing me.
When attempting to compile, sometimes the build fails because it says that Resources.Drawable doesn't contain a reference to two specific items. These are seek.xml and seek_style.xml.
However IntelliSense sees the expected value and if I look into Resource.designer.cs the values are there and when F12ing to the source the two entities are listed.
The two files are in the Resource/drawable folder and as mentioned before can be F12ed to during normal IntelliSense operations.
I've tried several guides to resolve this issue, including the one here: https://stackoverflow.com/a/36759115 but they only seem to provide temporary relief.
Does anyone have any suggestions? I'm tearing my hair out here.
Some screenshots:
File with reference (and working IntelliSense):
Content of Resources.Drawable:
Compile time errors:
Files in Drawable folder (with properties):
Resources/drawable folder − It stores all the images that you are going to use in your application.
Resources/values folder − It contains XML files to declare key-value pairs for strings (and other types) throughout an application. This is how localization for multiple languages is normally set up on Android.
You need to move the seek.xml and seek_style.xml files in Resources/Values folder and in properties window of xml files set:
I am creating three apps that are almost the same except some changes in the assets and raw files between them.
So I wanted to create a library from the first one, that will contain all the logic and activity and all the layouts and resources, and then import this library to the other two apps, and only change the assets and raw files.
the problem is that when the layout from the library loads, it is loading the assets from the library itself, and not the assets of the main app.
I am sure that my design here is wrong then I would also appreciate if someone can explain to me what is the right way to share activities and layouts as libraries in android.
NOTE: I don't want to use flavors. I want to build it as a completely different projects.
cheers
Since my application is growing more and more dense each day. I thought of re-structuring various files.
By re-structuring, I mean to add folders seperately for screen activites, another folder for dialog xmls, screen xmls, for custom adapters, etc. In other words, I need to segregate files according to their significance.
Currently, all my java files are listed in src folder (screen activities, custom adapters, business logic, etc.) and all the xmls (screens, custom list view design, custom dialogs, etc.) are present in layout folder.
Is it feasible? What impact will it have on the existing project?
Folders are synonymous with packages -- that's how the IDE interprets them. So putting them in separate folders actually creates separate packages. That's the downside, they won't have the same scope/permissions as if they were in the same package.
Packages in Java
What you're talking about is most likely packages.
Packages makes structuring of bigger projects and navigating through it much easier.
However you can't without writing your own gradle extension put your XML files outside /res/ folder, but codewise, wrapping your classes in packages makes working in bigger codebase much easier
You define the package you class is in before defining the imports in following way:
package com.ruuhkis.test;
import android.content.Context;
class Test {
}
then the Test class is put in folder /src/com/ruuhkis/test/ folder to be found by the compiler
I am trying to write a modular extensible application to deploy in Android. The idea is to provide an API to allow the creation of custom functionality for the app that may include custom layouts and other resources. This custom functionality will be loaded, at runtime, from another location (e.g. SD Card).
Currently I am able to load .jar files from this location and work with them as I like, unfortunately I can only include references to layouts and resources that are also present in the "Main" project.
I have been unable to find a good way to reference an entire library project, resources included. I essentially want each custom piece to contain all the resources it needs to display and run itself.
Right now I am toying with the idea of including an "Assets" project that can be referenced by each of the modules to be a central area to store layouts and other resources. Unfortunately this would require me to have a project that must be loaded by any other project that needs to be built.
Another idea was to include the layouts, images and strings, along with the jar files, in a folder and load those at run time. I don't think this will work well since the layouts seem to be pre-processed at compile time in some way and cannot be inflated at run time.
Does anyone know a way for me to include all the resources and code into a single, dynamically loadable, file that I can then access at runtime?
Does anyone know a way for me to include all the resources and code into a single, dynamically loadable, file that I can then access at runtime?
That is not supported. It is rather likely that it will never be supported, though it is possible that it might work with the new build system that is under development.
I have some sql queries that I would like to put in a .txt file and import to my application on start up. 2 questions:
1) Where is the best place to put these files?
2) I thought maybe I can put them in /res/raw/sql/ but the files don't come up with AutoComplete. (They come up if I put them in /res/raw/). Any ideas?
You cannot make sub folders of the resources folder Android provides per default. The same is true for the various layout folders etc. So you have to put them directly in /res/raw. But anyway, I think there it is the best place to save them.