前回の投稿に引き続き、複数の要素を に設定することはできました MultiAutoCompleteTextView
が、そのリンク画像のようにカスタム背景と閉じるボタンでそれらのアイテムをラップすることはできませんでした。
単一の要素で同じことを行うことができましたが、複数の場合は運がありませんでした。
これは私が試したものです。
// テキストを MultiAutoCompleteTextView に設定します
private void setTextSample(String contactName) {
final SpannableStringBuilder sb = new SpannableStringBuilder();
TextView tv = (TextView) LayoutInflater.from(this).inflate(R.layout.textview, null);
tv.setText(contactName);
BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(tv);
bd.setBounds(0, 0, bd.getIntrinsicWidth(), bd.getIntrinsicHeight());
sb.append(contactName + ",");
sb.setSpan(new ImageSpan(bd), sb.length()-(contactName.length()+1),
sb.length()-1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mMultiAutoCompleteTextView.setText(sb);
}
// テキストをカスタム要素でラップ
private static Object convertViewToDrawable(View view) {
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
view.measure(spec, spec);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.translate(-view.getScrollX(), -view.getScrollY());
view.draw(c);
view.setDrawingCacheEnabled(true);
Bitmap cacheBmp = view.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
view.destroyDrawingCache();
return new BitmapDrawable(viewBmp);
}
どんな助けでも大歓迎です。
編集 :
私が行った場合
mMultiAutoCompleteTextView.setText(mMultiAutoCompleteTextView.getText().toString()+", "+sb);
複数のテキストを取得していますが、カスタム背景でラップされていません。私が間違っているところに行きません。
編集 :
複数の要素のサンプルは次のようになります