What are the all if else conditions for span text
up vote
0
down vote
favorite
I am trying to use all the span condition (if else) for text styling but I am always getting an error as spanStart starts before 0 etc. Anyone can provide me which conditions I should check for giving style to my edit text. Here is my code
Spannable str = texto.getText();
int selStart = texto.getSelectionStart();
int selEnd = texto.getSelectionEnd();
StyleSpan styleSpans = texto.getText().getSpans(selStart, selEnd, StyleSpan.class);
for (StyleSpan styleSpan : styleSpans) {
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (selEnd > selStart)
if (oldStyle == Typeface.ITALIC)
str.removeSpan(styleSpan);
italicExists = true;
if (oldStyle == Typeface.BOLD_ITALIC)
str.setSpan(new StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
italicExists = false;
java android spannablestring spannable
add a comment |
up vote
0
down vote
favorite
I am trying to use all the span condition (if else) for text styling but I am always getting an error as spanStart starts before 0 etc. Anyone can provide me which conditions I should check for giving style to my edit text. Here is my code
Spannable str = texto.getText();
int selStart = texto.getSelectionStart();
int selEnd = texto.getSelectionEnd();
StyleSpan styleSpans = texto.getText().getSpans(selStart, selEnd, StyleSpan.class);
for (StyleSpan styleSpan : styleSpans) {
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (selEnd > selStart)
if (oldStyle == Typeface.ITALIC)
str.removeSpan(styleSpan);
italicExists = true;
if (oldStyle == Typeface.BOLD_ITALIC)
str.setSpan(new StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
italicExists = false;
java android spannablestring spannable
You're question is not very clear. Please review this and update for clarity: stackoverflow.com/help/how-to-ask
– dominicoder
Nov 11 at 7:01
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to use all the span condition (if else) for text styling but I am always getting an error as spanStart starts before 0 etc. Anyone can provide me which conditions I should check for giving style to my edit text. Here is my code
Spannable str = texto.getText();
int selStart = texto.getSelectionStart();
int selEnd = texto.getSelectionEnd();
StyleSpan styleSpans = texto.getText().getSpans(selStart, selEnd, StyleSpan.class);
for (StyleSpan styleSpan : styleSpans) {
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (selEnd > selStart)
if (oldStyle == Typeface.ITALIC)
str.removeSpan(styleSpan);
italicExists = true;
if (oldStyle == Typeface.BOLD_ITALIC)
str.setSpan(new StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
italicExists = false;
java android spannablestring spannable
I am trying to use all the span condition (if else) for text styling but I am always getting an error as spanStart starts before 0 etc. Anyone can provide me which conditions I should check for giving style to my edit text. Here is my code
Spannable str = texto.getText();
int selStart = texto.getSelectionStart();
int selEnd = texto.getSelectionEnd();
StyleSpan styleSpans = texto.getText().getSpans(selStart, selEnd, StyleSpan.class);
for (StyleSpan styleSpan : styleSpans) {
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (selEnd > selStart)
if (oldStyle == Typeface.ITALIC)
str.removeSpan(styleSpan);
italicExists = true;
if (oldStyle == Typeface.BOLD_ITALIC)
str.setSpan(new StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
italicExists = false;
java android spannablestring spannable
java android spannablestring spannable
asked Nov 11 at 4:18
S Shah
98110
98110
You're question is not very clear. Please review this and update for clarity: stackoverflow.com/help/how-to-ask
– dominicoder
Nov 11 at 7:01
add a comment |
You're question is not very clear. Please review this and update for clarity: stackoverflow.com/help/how-to-ask
– dominicoder
Nov 11 at 7:01
You're question is not very clear. Please review this and update for clarity: stackoverflow.com/help/how-to-ask
– dominicoder
Nov 11 at 7:01
You're question is not very clear. Please review this and update for clarity: stackoverflow.com/help/how-to-ask
– dominicoder
Nov 11 at 7:01
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245796%2fwhat-are-the-all-if-else-conditions-for-span-text%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You're question is not very clear. Please review this and update for clarity: stackoverflow.com/help/how-to-ask
– dominicoder
Nov 11 at 7:01