User11
User11

Reputation: 453

android unable to replace string value?

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

Upvotes: 0

Views: 65

Answers (2)

Axel
Axel

Reputation: 14149

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

index = index.replace(cs,":-)");

Upvotes: 4

Nir Hartmann
Nir Hartmann

Reputation: 1409

try to assign the value to index

index = index.replace(...

Upvotes: 1

Related Questions