I have a .txt file inside of my assets folder that has a massive HTML in it...
I call it to a string and set this string as a TextView's text:
InputStream is;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
tv = (TextView)findViewById(R.id.tv);
try {
is = getAssets().open("html.txt");
tv.setText(Html.fromHtml(convertStreamToString(is)));
} catch (Exception e) {
e.printStackTrace();
}
}
public static String convertStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
reader.close();
return sb.toString();
}
What I want to achieve is:
The TextView shows the text like it would show in a browser (I'm using
Html.fromHtml
to achieve this).When a user touches a word from that TextView, the word's background color changes (place a mark on this word and the mark will last even if the application is restarted).
Give the user an option to mark just the word, or the paragraph the word is in.
For the paragraph marking, I thought I could split the string into paragraphs, make a TextView for each paragraph, and set a click listener on it, to change the whole TextView's color...
For the words, I couldn't find any way to achieve that, except to split the HTML string into words and make a TextView for each word (the whole HTML has about 4000 words). And about storing the mark, I don't know either.
Could anyone help me please?