开发者

EditText: change images to string when copying?

开发者 https://www.devze.com 2023-02-05 06:38 出处:网络
I have an EditText that can contain images (emoticons). When I copy this text and paste it elsewhere, I get \"obj\" square instead of the image.

I have an EditText that can contain images (emoticons). When I copy this text and paste it elsewhere, I get "obj" square instead of the image.

Is there a way to change what is to be put in clipboard when copying (so that I can change the image object into a string)?

Edit 1: I guess I could create my own EditText class and override the method that is used when copying the text. Anyone kno开发者_如何转开发ws what method should I override? I tried "getText()", but it doesn't work...

Edit 2: Actually, it worked, but overriding this method changes the text in EditText, so it still isn't usefull...


Maybe this will be helpful:

public boolean onTextContextMenuItem(int id) {
    switch (id) {
    case android.R.id.copy:
        // override copy
        return true;
    case android.R.id.paste:
        // override paste
        return true;
    }
    return super.onTextContextMenuItem(id);
}


Have you tried creating a byte array of the image?

ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();


I do not know whether you solve the problem or not. I just have a post at stackoverflow_1527918

The method I used is to do a linear search on the editText.getText().toString to find the "obj" character. And then replace it with the image's link.

If you have any better idea, please tell me. Thank you.

0

精彩评论

暂无评论...
验证码 换一张
取 消