I have applied several formatting options in my app such as bold
, italic
, highlight
, underline
etc. all of these are saving the state through
Html.toHtml(editText.getText())
and getting that state through
Html.fromHtml(editText.getText())
finely. But the problem is with the bulleted list as bullets are not saved. What should I do to save the bulleted text and fetch it again in the same order (bulleted)?
I have tried the same for bullet list but it is not working while others are working correctly.
bullet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText tv = findViewById(R.id.text_write);
int selectionStart = tv.getSelectionStart();
int selectionEnd = tv.getSelectionEnd();
String string = tv.getText().toString();
String sub = string.substring(selectionStart, selectionEnd);
String arr[] = sub.split("\n");
int bulletGap = (int) dp(8);
SpannableStringBuilder ssb = new SpannableStringBuilder();
for (int i = 0; i < arr.length; i++) {
String line = arr[i];
SpannableString ss = new SpannableString(line);
//bullet list
ss.setSpan(new BulletSpan(bulletGap), 0, line.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// numbered list
// ss.setSpan(new NumberIndentSpan(bulletGap), 0,line.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(ss);
//avoid last "\n"
if (i + 1 < arr.length)
ssb.append("\n");
}
int start = Math.max(tv.getSelectionStart(), 0);
int end = Math.max(tv.getSelectionEnd(), 0);
tv.getText().replace(Math.min(start, end), Math.max(start, end),
ssb, 0, ssb.length());
bullet.setBackgroundResource(R.drawable.button_menu);
}
});
save(editTitle.getText().toString(), Html.toHtml(editText.getText()), txt.getText().toString(), currentDateandTime, currentDateandTime);//it is saving the data in sqlite database
if (description!=null)
editText.setText(Html.fromHtml(description));//it is saving all other states rather than bullet list.
There is no error message. Whenever I open the activity all the other text i.e. bolded, italicized etc. text is fetched correctly but bullets are cleared.
- ` tags manually.
– Froyo Jun 19 '19 at 14:28