2

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.

c-an
  • 3,543
  • 5
  • 35
  • 82
Mehwish Mustafa
  • 41
  • 1
  • 10
  • `Html.fromHtml()` will convert HTML marked up text and display it. When you store the description in your database, are you adding html tags for bullets? Otherwise, it won't work, you would have to manually add bullet points. Also, `\n` in html means nothing. It would just ignore it. – Froyo Jun 19 '19 at 13:54
  • Can you please explain what does it mean "are you adding html tags for bullets?" – Mehwish Mustafa Jun 19 '19 at 14:02
  • 1
    1. You are creating bullet span for each new line. Then you set this spannable to your edit text. 2. When you save it using `Html.toHtml()`, these spans are discarded since these are not related to html. So when you save, you would need to add `
    • ` tags manually.
    – Froyo Jun 19 '19 at 14:28

0 Answers0