HI everyone, I have a bunch of text in an Edit text that I have set up to be styled(strike through only for the moment) using the setSpan method in Android. This seems to work fine.
The trouble I am having is that all the styling seem to get cancelled once I close that activity. That is when I load up the activity again , it just has plain text and none of the styling I had applied using the setSpan().
Note: All of my text get stored in a Database.
I have attached all the code for the styling, let me know if you need to see any more bits of code.
private void doStrick() {
int selectionStart = mBodyText.getSelectionStart();
styleStart = selectionStart;
int selectionEnd = mBodyText.getSelectionEnd();
// check for boo-boo's
if (selectionStart > selectionEnd){
int temp = selectionEnd;
selectionEnd = selectionStart;
selectionStart = temp;
}
Spannable str = mBodyText.getText();
str.setSpan(new StrikethroughSpan(),selectionStart, selectionEnd, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
Is that some bit of code I need to be adding to save the styling?
EDIT based on answer:
Calendar cal=Calendar.getInstance();
String date_time=String.format("%1$te %1$tB %1$tY,%1$tI:%1$tM:%1$tS %1$Tp",cal);
float Textsize = mBodyText.getTextSize();
String title = mTitleText.getText().toString();
String body = Html.toHtml(mBodyText.getText());
if (mRowId == null) {
long id = mDbHelper.createNote(title, body, date_time, Textsize);
if (id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateNote(mRowId, title, body, date_time, Textsize);
Log.d("MYTAG", "updateing note");
updateWidget();
And where I populate the fields:
Cursor note = mDbHelper.fetchNote(mRowId);
startManagingCursor(note);
mTitleText.setText(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(Html.fromHtml(note.getString(
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY))));
mBodyText = (EditText) findViewById(R.id.body);
float size = note.getFloat(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TEXT_SIZE));
mBodyText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);