简体   繁体   中英

Adding non-android xml file to android project

I have problems with adding a non-android xml file init.xml to android project in Eclipse. This file is used to initialize some simulation process, which is not connected with android. Eclipse doesn't recognize it if simply put it into project directory and write something like

File file = new File("init.xml");

Should I declare the file in some specific way or put it into other directory?

You can put this file inside the assets folder and then you can access this file by using AssetManager and getAssets() .

AssetManager assetManager = getAssets();
InputStream instream = assetManager.open("init.xml");

Put it into the /res/xml directory and access it as a resource with Resources.getXML() .

See: http://developer.android.com/guide/topics/resources/providing-resources.html

您应该将这些文件放在assets/目录中,然后通过AssetManager进行访问。

为什么不将它放在资产文件夹中,要从那里获取它,只需使用以下命令:

Activity.getAssets().open(...) //with your file..

you can put the file res/layout and dont forget 2 give extension .xml i hope it would be already wd extension .xml

and you can acces that xml on source page like

(R.layout.xml name )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM