Hopefully, this is a newbie question with a quick answer...
I am attempting to add a simple preferences file in a new Android project (New -> Android XML File), but it doesn't appear to be working correctly.
There is no root element to choose from when I select the Preference type layout. If I press Finish, it doesn't do anything. See screenshot below.
Thanks,
wTs
Just create a normal xml file to the project /res/xml/ folder and add your content to the file as usual. Should work just great. Eclipse detects it as a preference file once you have added the preference-xml and saved it.
You don't need to have a root element in the selection screen. Just replace whatever eclipse generates with what you want.
try refreshing the folder that the file is supposed to be in (in your example res/xml).
Related
I am a beginner in android and I am learning it by watching tutorials on YouTube. I completed all the initial steps for building up an android project but I am unable to find out any main.xml file or activity_main.xml file under res/layout folder. In fact, the layout folder is not even showing any drop down menu. I googled my doubts but I am unable to find any satisfactory answer. Can someone please tell me what exactly went wrong ?
Add your own activity_main.xml file to the layout folder. Right click layout -> New -> Android XML File -> Name the file activity_main and click Finish.
At least if you have the MainActivy.class file, (the launcher activity), the ide, wheater android studio or eclipse should show you if the you layout activity exist by underlining the parameters for the 'setcontentlayout()' function if it doesnt exist. The 'setoptionsmenu()' function also do the same. if they are there, your MainActivity.class should be free from errors otherwise create them and insert them.
For example, if I had something like
setContentView(R.layout.activity_main);
Would there be a shortcut to open activity_main.xml? If not, is there a way to create one?
Its there. Just hold Ctrl and move the cursor to the word activity_main which is the line setContentView(R.layout.activity_main); then, it will be give two option that one is for opening xml layout and another one is opening the declaration in R.java file. This is the shortcut to open the XML layout easily.
Cheers!
This is not exactly a shortcut, but you can highlight the activity_main part on that setContentView(R.layout.activity_main); line and then press Ctrl+Shift+R.
The Open Resource dialog that shows up should have activity_main.xml (along with other files with activity_main in their names) at the top of the list. Just press Enter to open the one you want.
Actually its an id. When you create an XML file in android automatically that file has given an id by Android and you can find it into gen folder and the class name is R.java. So if you want to see that file you have to open res folder -> layout folder -> there you can see that xml file.
But you can do it as #joe or #Spk has suggested you. And Spk's solution is far better. So cheers.
if you have the class file opened instead of the java file it probably wont work. But in the java file press control on windows or command on mac and hover over the element for options to navigate.
I have started a new Android empty project.
Where can i find the graphical layout switch button ?
I have Eclipse Java EE and didn't installed any ADT plug-ins
because i am guessing they are already installed.
Do i need to put initial code before i'll be able to use it?
i read that i need to open the XML file to use the graphical layout,
the only xml file that i found is the manifest.
and accessing this file didn't get any result.
thanks,
Rami
You will find the layout xml files in /res/layout/*.xml.
These are the files that when opened will have a graphical editor.
If there aren't any then you can make one by using the new XML wizard.
my Android xml fle Design look like this.
but i want to view like this so how can do this?
Right click on xml and select open with -> Android XML Resources Editor and also
you can try open with -> Android Layout Editor to have Design Layout tab.
I also faced this problem earlier for all xml files but not for manifest file ,now it resolved
in my application our requirement is When the orientation of the activity changes place the appropriate land folder and xml files.in that we give wrong naming conventions for the layout folders instead of layout-land,layout-land-hdpi,layout-land-mdpi,layout-land-ldpi,layout-port,layout-port-hdpi,layout-port-mdpi,layout-port-ldpi when ever we correct the naming conventions it comes normally.
I am beginner in android so some beginer problems is occured. I create second activiy and second layout xml file named getNearest.xml. The code section to show this file is
setContentView(R.layout.getNearest)
But eclipse cannot be find getNearest. It only shows .main. So what is the problem with this?
You need to build at least once to have the R.layout values updated when you create a new layout. Also make sure you saved the layout file and that it exists under the res\layout folder.