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..

User11
  • 453
  • 5
  • 21

2 Answers2

4

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

index = index.replace(cs,":-)");
Axel
  • 13,939
  • 5
  • 50
  • 79
  • i have to ask one more thing.,can we convert spannble object into string?? – User11 May 12 '14 at 08:47
  • 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? http://stackoverflow.com/questions/14900449/storing-spannable-to-a-string – Axel May 12 '14 at 10:13
1

try to assign the value to index

index = index.replace(...
Nir Hartmann
  • 1,389
  • 12
  • 14