Code example for ImageSpan

0
				Bitmap bitmap = convertViewToDrawable(tv);
				BitmapDrawable bmd = new BitmapDrawable(getResources(), bitmap);
				bmd.setBounds(0, 0, bmd.getIntrinsicWidth(),bmd.getIntrinsicHeight());
 
				// Add the span (containing the channel's label) on the SpannableStringBuilder, following the previous 
				ssb.setSpan(new ImageSpan(bmd), x, x + c.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 
				// Make the span text clickable : if the user clicks on a span, he removes the span. 
				// (implicit call of the method afterTextChanged) 
				ClickableSpan clickSpan = new ClickableSpan() {
 
					@Override 
					public void onClick(View view) {
						int i = ((EditText) view).getSelectionStart();
						int j = ((EditText) view).getSelectionEnd();
						// Manage the following case : the user has removed the space following the span 
						if(getText().toString().contains(" ")){
							getText().replace(Math.min(i, j), Math.max(i, j)+1, "", 0, 0); // +1 for the space
						} 
						else{ 
							getText().replace(Math.min(i, j), Math.max(i, j), "", 0, 0); // if the user has removed the space