質問

I am making a chat application in which I am using emoticons functionality. My emoticons are working properly but the problem is:

  1. When I send only one smile, it works properly

  2. I want to send more then one image in edittext or dialog, here is image snapshot:

enter image description here

Here is my code:

   builder = new SpannableStringBuilder(message1);
        if(message1.contains("x-(R"))
        {

            int len=message1.indexOf("x-(R");
            while(len!=-1)
            {
                builder.replace(len, len+4, getSmiley(1));

                message1=message1.replaceFirst("x-\\(R", "");
                len=message1.indexOf("x-(R");
            }
        }

For sending and showing the image, where am I going wrong?

役に立ちましたか?

解決

You can go with getSmiley(1).toString(). it will work ?

Like message1=message1.replaceFirst("x-\(R", getSmiley(1).toString());

他のヒント

The only problem I see is that you replace a string in the builder with getSmiley(1) (assume this is not empty string), then in message1 you replace X-R( with empty string. message1 and builder are not in sync anymore after the first replace. So when you get the len for second time ( len=message1.indexOf("x-(R"); ) you replace wrong index in the builder.

Maybe the correct thing to do is to replace the message like the builder:

message1=message1.replaceFirst("x-\\(R", getSmiley(1));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top