I have several cases where my string in strings.xml is quite long and has multiple lines done with \n.
Editing however is quite annoying since it is a long line in Eclipse.
Is there a better way to edit this so it looks like it will be presented later in the textview, ie the line breaks as line breaks and the text in multiline edit mode?
Two possibilities:
XML allows literal newline characters in strings:
<string name="breakfast">eggs
and
spam</string>
You just have to edit the XML code instead of using the nifty Eclipse GUI
Everything inside the assets
directory is available as a input stream from the application code.
You can access those file input streams of assets with AssetManager.open()
, a AssetManager
instance with Resources.getAssets()
, and… you know what, here’s the Java-typical enormously verbose code for such a simple task:
View view;
//before calling the following, get your main
//View from somewhere and assign it to "view"
String getAsset(String fileName) throws IOException {
AssetManager am = view.getContext().getResources().getAssets();
InputStream is = am.open(fileName, AssetManager.ACCESS_BUFFER);
return new Scanner(is).useDelimiter("\\Z").next();
}
the use of Scanner
is obviously a shortcut m(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With