Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok I found a good solution I tweaked and simplified a bit, it is here: <a href="http://www.kpbird.com/2013/02/android-chips-edittext-token-edittext.html" rel="nofollow">http://www.kpbird.com/2013/02/android-chips-edittext-token-edittext.html</a></p> <p>Basically I extended the <code>MultiAutoCompleteTextView</code>. I also created a custom separator for using space, but this is not of importance and can be found elsewhere. I have commented in code where this should be changed to a comma.</p> <p>I added a custom <code>TextWatcher</code> implementation where I implemented the <code>onTextChange</code> method to run the method I called bubbleWord() (mostly taken from the above mentioned source)</p> <pre><code>private void bubbleWord() { int numberOfBubbles = 0; String triggersString = getText().toString(); //note that I use space as a separator if (triggersString.contains(" ")) { SpannableStringBuilder ssb = new SpannableStringBuilder( getText()); BubbleMultiAutoCompleteTextView.this .setTriggersArray(triggersString.trim().split(" ")); String[] triggers = BubbleMultiAutoCompleteTextView.this .getTriggers(); for (String trigger : triggers) { LayoutInflater lf = (LayoutInflater) getContext() .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); TextView textView = (TextView) lf.inflate( R.layout.bubble_edit, null); textView.setText(trigger); // 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 @SuppressWarnings("deprecation") BitmapDrawable bmpDrawable = new BitmapDrawable(viewBmp); bmpDrawable.setBounds(0, 0, bmpDrawable.getIntrinsicWidth(), bmpDrawable.getIntrinsicHeight()); // create and set imagespan ssb.setSpan(new ImageSpan(bmpDrawable), numberOfBubbles, numberOfBubbles + trigger.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); numberOfBubbles = numberOfBubbles + trigger.length() + 1; } // set chips span setText(ssb); // move cursor to last setSelection(getText().length()); } } </code></pre> <p>In the layout folder this file was included (same as before, almost the same as the source but a bit different):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/edtTxt1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#9191B5" android:drawablePadding="2dp" android:drawableRight="@drawable/exclamation_octagon_fram" android:padding="8dp" android:shadowColor="#FFFFFF" android:shadowDy="1" android:shadowRadius="0.01" android:textColor="#FFFFFF" android:textSize="18sp" android:textStyle="bold" /&gt; </code></pre> <p>Please let me know if anyone needs this and I have forgotten something.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload