久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何獲得類似于 Facebook 應用程序的 MultiAutoCompl

How do I get MultiAutoCompleteTextView tokenizer similar to Facebook app?(如何獲得類似于 Facebook 應用程序的 MultiAutoCompleteTextView 標記器?)
本文介紹了如何獲得類似于 Facebook 應用程序的 MultiAutoCompleteTextView 標記器?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在創建一個具有收件人"字段的應用程序,就像 Facebook 應用程序的新消息"功能一樣.

I am creating an application which has a 'To' field just like in Facebook app's "New Message" feature.

從下拉列表中選擇一個項目后,我創建一個圖像跨度并將其添加到 MultiAutoCompleteTextView.我為這個視圖使用了 SpaceTokenizer .問題是當我單擊退格時,光標首先移動到空白處(即空格 Tokenizer),然后當我再次單擊退格時,整個單詞被刪除....我想在我第一次單擊退格時刪除整個單詞,就像 facebook 應用程序一樣...

After selecting an item from the drop down list, I create an imagespan and add it to the MultiAutoCompleteTextView. I have used SpaceTokenizer for this view . The problem is when I click on backspace, the cursor first moves to the empty space (i.e., space Tokenizer) and then when I click on the backspace again, the whole word gets deleted....I want to delete the whole word on my first click of backspace just like facebook app...

這是我的 SpaceTokenizer

     multiContentText.setTokenizer(new Tokenizer(){
     public int findTokenStart(CharSequence text, int      cursor) {
        int i = cursor;
        if(i>0){
            Log.d("textchar ",""+text.charAt(i - 1));
        }

        while (i > 0 && text.charAt(i - 1) != ' ') {
            i--;
        }
        while (i < cursor && text.charAt(i) == ' ' || text.charAt(i - 1) == '
') {
            i++;
        }

        return i;
    }

    public int findTokenEnd(CharSequence text, int cursor) {
        int i = cursor;
        int len = text.length();

        while (i < len) {
            if (text.charAt(i) == ' ' || text.charAt(i - 1) == '
') {
                return i;
            } else {
                i++;
            }
        }

        return len;
    }

    public CharSequence terminateToken(CharSequence text) {
        int i = text.length();
        while (i > 0 && text.charAt(i - 1) == ' ' || text.charAt(i - 1) == '
') {
            i--;
        }

        if (i > 0 && text.charAt(i - 1) == ' ' || text.charAt(i - 1) == '
') {
            return text;
        } else {
            if (text instanceof Spanned) {                               
                SpannableString sp = new SpannableString(text + " ");
                TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                                        Object.class, sp, 0);
                return sp;
            } else {                                 
                return text+" ";
            }
        }
    }
});

我正在使用此代碼在我的 multi-ContentText 中創建一個 TextView

I am using this code to create a TextView in my multi-ContentText

SpannableStringBuilder ssb = new SpannableStringBuilder(multiContentText.getText());
String c="text from the list";
TextView textView = (TextView) inflater.inflate(R.layout.chips_edittext, null);
textView.setText(c); // set text
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true); 
textView.destroyDrawingCache();  // destory drawable
// create bitmap drawable for imagespan
BitmapDrawable bmpDrawable = new BitmapDrawable(viewBmp);               
bmpDrawable.setBounds(0, 0,bmpDrawable.getIntrinsicWidth(),bmpDrawable.getIntrinsicHeight());
// create and set imagespan 
ssb.setSpan(new ImageSpan(bmpDrawable),0 ,c.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// set chips span 
multiContentText.setText(ssb);      
multiContentText.setSelection(multiContentText.getText().length());

我不確定空格 Tokenizer 是否是此類行為的正確選擇...任何幫助或指針將不勝感激...

I am not sure whether the space Tokenizer is the right option for this type of behavior...Any help or pointers will be grateful...

這里是截圖以便更好地理解......

Here is the screenshot for better understanding....

我有一個文本,后跟一個空格,然后是一個光標...如果我按退格鍵,它首先會移動到空白處,只有當我再次按退格鍵時,整個文本才會被刪除....

I have a text followed by a space and then a cursor...If I hit backspace, it first moves to the empty space and only when I hit backspace again the whole text is deleted....

這是另一個截圖..

這里的光標并不完全位于兩個 TextView 之間,這與 facebook 應用程序不同,這再次導致插入文本時出現一些問題...

Here the cursor is not exactly in between the two TextViews unlike in facebook app which again causes some issues in inserting the text...

推薦答案

找到解決方案....

將此文本觀察器添加到多自動完成文本視圖

Add this textwatcher to the multiautocompletetextview

private TextWatcher textWather = new TextWatcher() {
    int noOfCharAdded=0;int noOfCharDeleted=0;
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        startIdx=start;
    }
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,int after) {
        noOfCharAdded=after;
        noOfCharDeleted=count;
    }
    @Override
    public void afterTextChanged(Editable s) {
        Editable buffer = s;
        int start = multiContentText.getSelectionStart()<0?0:multiContentText.getSelectionStart();
        int end = multiContentText.getSelectionEnd()<0?0:multiContentText.getSelectionEnd();
                if(noOfCharAdded==0 && noOfCharDeleted==1){ //if space is deleted
                        if (start == end && delPrevText) {                          
                            ImageSpan link[] = buffer.getSpans(start, end,ImageSpan.class);
                            if (link.length > 0) {                                  
                                buffer.replace(buffer.getSpanStart(link[0]),buffer.getSpanEnd(link[0]),"");
                                buffer.removeSpan(link[0]);
                            }
                        }
                        delPrevText=true; 
                        multiContentText.setSelection(multiContentText.getText().length());
                }
                else if(noOfCharAdded==0 && noOfCharDeleted>1){//if the whole word is deleted
                        if(buffer.length()>0){                                           
                            if(start<buffer.length()){
                               delPrevText=false;                                  
                               if(buffer.charAt(start)==' '){                                       
                                  buffer.replace(start,start+1,"");
                               }
                            }
                        }                      
                }               

    }
};

這篇關于如何獲得類似于 Facebook 應用程序的 MultiAutoCompleteTextView 標記器?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 91亚洲精华国产 | 天天草夜夜骑 | www.久久.com| 国产精品午夜电影 | 999国产精品视频 | 成人欧美一区二区 | 国产一级一级国产 | 亚洲女人天堂成人av在线 | 亚洲欧美一区二区三区国产精品 | 国产乱码精品一区二区三区忘忧草 | 2022国产精品| 午夜精品一区 | 精品亚洲一区二区三区 | 精品熟人一区二区三区四区 | 成人h视频| 国产成人高清视频 | 色婷婷综合久久久久中文一区二区 | 欧美精品一区二区三区在线播放 | 91精品国产一区二区三区蜜臀 | 国产一级毛片视频 | 久草福利 | 成人免费视屏 | 精品国产欧美在线 | 91久久精品国产免费一区 | 97精品国产| 欧美激情精品久久久久久变态 | 日韩有码一区 | 久久国产高清视频 | 久优草 | 久久久久久亚洲 | 成人超碰 | 免费黄色片视频 | 欧美videosex性极品hd | 久久亚洲精品国产精品紫薇 | 日韩理论电影在线观看 | 久久国产视频网站 | 日韩在线中文字幕 | 精品免费国产一区二区三区四区介绍 | 亚洲啪啪一区 | 91精品国产91久久久久久 | 九九热久久免费视频 |