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;











share|improve this question





















  • 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














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;











share|improve this question





















  • 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












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;











share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3