android如何在xmpp中分离edittext中的跨对象?

android如何在xmpp中分离edittext中的跨对象?,android,xmpp,Android,Xmpp,我正在制作一个聊天应用程序,其中我正在使用表情功能。我的表情功能对于单个图像正常工作,但当我拍摄多个表情图像时,它不会转换为特定的图像。有时只有单个图像正在转换,我的问题是 我无法在编辑文本字段中分离跨距对象。对于单个值,它正在工作,但对于多个值,它不工作。。 例如,我在编辑文本字段中拍摄了4幅不同的图像,如下所示 现在我想分离它的跨对象,我该怎么做呢 这是代码 public void keyClickedIndex( final String index) { ImageGet

我正在制作一个聊天应用程序,其中我正在使用表情功能。我的表情功能对于单个图像正常工作,但当我拍摄多个表情图像时,它不会转换为特定的图像。有时只有单个图像正在转换,我的问题是

我无法在编辑文本字段中分离跨距对象。对于单个值,它正在工作,但对于多个值,它不工作。。 例如,我在编辑文本字段中拍摄了4幅不同的图像,如下所示

现在我想分离它的跨对象,我该怎么做呢 这是代码

 public void keyClickedIndex( final String index) 
{

    ImageGetter imageGetter = new ImageGetter() 
    {
        public Drawable getDrawable(String source) 
        {    
            StringTokenizer st = new StringTokenizer(index, ".");
            Drawable d = new BitmapDrawable(getResources(),emoticons[Integer.parseInt(st.nextToken()) - 1]);
            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
            return d;
        }
    };


    Spanned cs = Html.fromHtml("<img src ='"+ index +"'/>", imageGetter, null);        
    int cursorPosition = mSendText.getSelectionStart();     
        mSendText.getText().insert(cursorPosition, cs);

请帮助我…,提前谢谢。

您可以使用表情处理程序方法

private static class EmoticonHandler implements TextWatcher {

    private final EditText mEditor;
    private final ArrayList<ImageSpan> mEmoticonsToRemove = new ArrayList<ImageSpan>();
    //public String txt;
    XMPPClient act;
    public EmoticonHandler(EditText editor,XMPPClient act) {
        // Attach the handler to listen for text changes.
        mEditor = editor;
        mEditor.addTextChangedListener(this);
        this.act = act;
    }

    public void insert(String emoticon, int resource) 
    {
        // Create the ImageSpan
        Drawable drawable = mEditor.getResources().getDrawable(resource);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        ImageSpan span = new ImageSpan(drawable,emoticon,ImageSpan.ALIGN_BASELINE);

        // Get the selected text.
        int start = mEditor.getSelectionStart();
        int end = mEditor.getSelectionEnd();
        Editable message = mEditor.getEditableText();

        // Insert the emoticon.
        message.replace(start, end, emoticon);
        message.setSpan(span, start, start + emoticon.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    @Override
    public void beforeTextChanged(CharSequence text, int start, int count, int after) {
        // Check if some text will be removed.
        if (count > 0) {
            int end = start + count;
            Editable message = mEditor.getEditableText();
            ImageSpan[] list = message.getSpans(start, end, ImageSpan.class);

            boolean check = false;

            for (ImageSpan span : list)
            {
                // Get only the emoticons that are inside of the changed
                // region.

                check = true;
                int spanStart = message.getSpanStart(span);
                int spanEnd = message.getSpanEnd(span);
                //txt = text.toString();
                act.emorTxt =  text.toString();
                if ((spanStart < end) && (spanEnd > start)) {
                    // Add to remove list
                    mEmoticonsToRemove.add(span);
                }
            }

            if(!check)
            {
                act.emorTxt =  text.toString();
            }
        }
    }

    @Override
    public void afterTextChanged(Editable text) {
        Editable message = mEditor.getEditableText();

        // Commit the emoticons to be removed.
        for (ImageSpan span : mEmoticonsToRemove) 
        {
            int start = message.getSpanStart(span);
            int end = message.getSpanEnd(span);

            // Remove the span
            message.removeSpan(span);

            // Remove the remaining emoticon text.
            if (start != end) {
                message.delete(start, end);
            }
        }
        mEmoticonsToRemove.clear();


    }

    @Override
    public void onTextChanged(CharSequence text, int start, int before, int count) {
    }

}

它会很好地工作……:

分开吗?你是什么意思?@pskink seprate的意思是,我想知道特定对象的图像。在编辑文本中,它是微笑、悲伤或其他任何东西。我不知道你在说什么want@pskink你能帮我个忙吗…,如何在这个问题上增加悬赏?你的问题不清楚:没有人会知道你想要什么