Why when I import a Text File to my project it shows me an error?
I need the text file to read some info from it and display it on a ListView. Here is a screenshot of what I am talking about.
Why when I import a Text File to my project it shows me an error?
I need the text file to read some info from it and display it on a ListView. Here is a screenshot of what I am talking about.
All data files in this directory must be XML format.
There are several kinds of data you can put here. See http://developer.android.com/guide/topics/resources/more-resources.html for details.
For example:
res/values/strings.xml
<string name="prefs">Version</string>
would be referenced in Java code as
String version = context.getResources().getString(R.id.prefs);
You cannot use a textile to fill a ListView, you should set it on strings.xml, add the String name and his value. @String can be stored and retrieved as resources.
To open raw resources, you need to use openRawResource()
.
For example, if you're in an Activity
, you can open the raw text file as:
InputStream input = getResources().openRawResource(R.raw.textfile);
This returns an InputStream, which allows you to read from your file.
This SO question provides a nice code sample for basic reading of a raw text file.