Android layout XML files in a subdirectory not being found - android

I tried to organized my layout.xml files, and made a directory
/res/layout/content/
Then I tried to point to a file there from the code like this:
setContentView(R.layout.content.product_strategy);
but I get an error that the content is not a field that can be resolved.
What am doing wrong?
Thanks!

You can't make your own resource folder in android.
Please take a look at this link provding information about resource folders:
http://developer.android.com/guide/topics/resources/providing-resources.html

R.java doesn't create references to subdirectories in resources. That's the reason. So you need to use the single level default directory structure.

Related

Is it possible to create multiple directories for drawable in res?

So I have tried creating new directories by right clicking the res folder then on new--> Android Resource Directory.Then I changed the Resource Type to drawable.
After doing all that I copied my images into this new directory that I have created and when I try to assign them to an imageview that was not assigned yet an image through the xml with the command android:src="#mydir/mypic" android studio does not recognise my custom folder name. Is this even possible?
I am using android studio 2.2.3
You can't create subfolders for drawables in the res/drawable folder.
See this question here in SO.
Can the Android drawable directory contain subdirectories?
#Aris I think it is possible to create multiple directories using gradle,
I read on mediumn about Android Project Structure - Alternative way
Please check this link,
https://medium.com/google-developer-experts/android-project-structure-alternative-way-29ce766682f0
Please read Conclusion carefully.
Thanks

Put image in drawable folder?

I put an image in my res/drawable folder, but when I clean and build my project, I receive the error message R cannot be resolved. I don't understand why this happens, what should I do?
Check out the following link:
http://source.android.com/source/using-eclipse.html
Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.
After removing the erroneous imports, delete your R.java file and try to clean and build the project again. If the problem still persists, post here.
possible causes:
duplicate file names (across all drawables folders) . for example , is there a file named "h1.png" and also "h1.jpg" ?
bad files names . only letters allowed are lowercase english ones , and digits.
hidden files , like those of the OS . on windows , it's probably "Thumb.db" . either delete them , or delete & disable them. linux and mac also have such files , but with different names and usually start with "." .
Make sure your image name is in small latters and in res/drawable folder.for how we add drawables in our project and supported images formats see docs Drawable Resources
Might be you are using android.R.drawable.your_image
Remove android.R from imports. use R.drawable.your_image
For Android Studio:
Right click on res, new Image Asset
On Asset type choose Action Bar and Tab Icons
Choose the image path
Give your image a name in Resource name
Next->Finish
The image will be saved in the /res/drawable folder!

how to distinguish layout folder in android?

I have a fairly complex android app, the contents of the 'layout' folder is becoming increasingly large. I've tried to organise the individual layout xml files into sub folders e.g. layout/dialog/, layout/activity/, layout/views/ etc. This doesn't seem to work, the content of the folders in not parsed into the R. class.
Is there a way to do this?
Thanks!
Short answer is no, subfolders are not supported. You probably just need to get clever with naming the files. See this question: Can the Android drawable directory contain subdirectories?
Resource directories should be flat. So, if your intention is to have layout/dialog, layout/activity/, layout/views/, etc. you should go with layout/dialog_whatever, layout/activity_whatever and layout/views_whatever, which gives you more or less the same organization.
No, resource directories doesn't support sub directories structures, Because it all about indexing in your R.java files,
You have to give naming conversion for your files, like, layout/activity_..
If you have more xml layout in your app then you have to give the proper naming convention as the xml use in the perticular activity.
as like if your activities are like activity1, activity2 and the xml in that activities are dialog1.xml, dialog2.xml, main1.xml, main2.xml, button1.xml, button2.xml, view1.xml, view2.xml ...etc
Then use that xml layout with naming convention as like:
layout\activity1_dialog1.xml
layout\activity1_main1.xml
layout\activity1_button1.xml
layout\activity1_view1.xml
layout\activity2_dialog2.xml
layout\activity2_main2.xml
layout\activity2_button2.xml
layout\activity2_view2.xml
Hope you got my point. It will realy help you to manage the xml layout as i am doing same thing.
Enjoy. :)

Layout file and r.java

Is it possible to convert R.java into layout file xxx.xml..
In some project which I got from internet the layout file is missing and all I have now is R.java.
So is there any way that I can create/extract information from R.java file to make the layout xml file.
That is not possible. the R class only handles references to content (like layouts), not the content itself.
R.Java is the pretty much the only file that you don't need. This file is automatically generated when your project is compiled.
Because of this, you should not edit this file in any way.
Therefore, if all you have is the R.java file... Well, you have nothing.
you can't do that, if R.java deleted your only way is add the xml again. i think create layout programmatically in android better than with xml. because the R doesn't need to generate. but the weakness of programmatical layout is you must declare id by your self. generate or manual which one do you like :)

Android: Refactoring XML files in Eclipse?

Is there a way to easily rename XML files in Eclipse while developing for Android so that these changes are reflected in source code?
Right-clicking on the file in package view and selecting refactor->rename changes the file's name, but does not alter references to the file within the .java source files.
I realise this is an old post, but i was trying to do the same and just came up with a solution to this in eclipse:
Search -> File Search -> Replace...
Replace:Current.Style.Name
With: New.Style.Name
Thats it! Nice and easy, i didn't want to deal with the hassle of going into all my xml layouts and changing them.
I do not think such a thing exists for Android resources directory let alone layouts. You have to change the references manually.

Categories

Resources