0

i am making a chat application,in which i am providing emoticons functionality ,for sending image icon in chat.,for that i have putted all the code.,now the problem is my string text is not converting and repalcing to ":-)" this icon.

I don't know where i am wrong,please help em..,i am searching for the solution from 3 days..but not getting any satisfactory solution,here is my code

 Spanned cs = Html.fromHtml("<img src ='"+ index +"'/>", imageGetter, null);        
    int cursorPosition = mSendText.getSelectionStart();
 String imagename="1.png";      
    mSendText.getText().insert(cursorPosition, index);
    if (index.contains(imagename)) {
        index.replace(cs,":-)");
        mSendText.setText(index);

    } else {
        Log.i("errororrr",index);
    }
    //      mSendText.getText().insert(cursorPosition, index);
    //mSendText.setText(index);

}

this is the code for converting and replacing.

Thanks in advance..

2 Answers 2

4

String is immutable in Java. If you want to replace something in a String, you have to use this:

index = index.replace(cs,":-)");
Sign up to request clarification or add additional context in comments.

2 Comments

i have to ask one more thing.,can we convert spannble object into string??
Spannable has a toString() method likje every other Java class, so yes you can. However I do not know the output you will get. But since you are talking about emoticons, have you looked at this question? stackoverflow.com/questions/14900449/…
1

try to assign the value to index

index = index.replace(...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.