I know I can put escaped HTML tags in string resources. However, looking at the source code for the Contacts application I can see that they have a way of not having to enco
Idea: put the HTML in JSON-formatted files and store them in /res/raw. (JSON is less picky)
Store the data records like this in an array object:
[
{
"Field1": "String data",
"Field2": 12345,
"Field3": "more Strings",
"Field4": true
},
{
"Field1": "String data",
"Field2": 12345,
"Field3": "more Strings",
"Field4": true
},
{
"Field1": "String data",
"Field2": 12345,
"Field3": "more Strings",
"Field4": true
}
]
To read the data in your app :
private ArrayList getData(String filename) {
ArrayList dataArray = new ArrayList();
try {
int id = getResources().getIdentifier(filename, "raw", getPackageName());
InputStream input = getResources().openRawResource(id);
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
String text = new String(buffer);
Gson gson = new Gson();
Type dataType = new TypeToken>>() {}.getType();
List
Finally, the Data
class is just a container of public variables for easy access...
public class Data {
public String string;
public Integer number;
public String somestring;
public Integer site;
public boolean logical;
public Data(String string, Integer number, String somestring, boolean logical)
{
this.string = string;
this.number = number;
this.somestring = somestring;
this.logical = logical;
}
}