0
刪除事件在我的應用程序已經使用的芯片使用Chips。而且它工作正常。當用戶添加聯繫人時,其ID將保存在數組列表中。問題是當用戶使用軟鍵盤上的刪除按鈕刪除聯繫人時,我將如何從arraylist中刪除其ID。如何將芯片連接到它的ID。請幫助我。提前感謝。爲聯繫人選擇獲取芯片的Android
以下代碼用於創建芯片。
public void setChips() {
if (friends_multiautocomplete_tv.getText().toString().contains(";")) // check
// semicolon
// in
// string
{
SpannableStringBuilder ssb = new SpannableStringBuilder(
friends_multiautocomplete_tv.getText());
// split string with semicolon
String chips[] = friends_multiautocomplete_tv.getText().toString()
.trim().split(";");
int x = 0;
// loop will generate ImageSpan for every name separated by
// semicolon
for (String c : chips) {
// inflate chips_edittext layout
LayoutInflater lf = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
TextView textView = (TextView) lf.inflate(
R.layout.chips_edittext, null);
textView.setText(c); // set text
Typeface tfNormal = Typeface.createFromAsset(getAssets(),
"SourceSansPro-Regular.ttf");
textView.setTypeface(tfNormal);
// capture bitmapt of genreated textview
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), x, x + c.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
x = x + c.length() + 1;
}
// set chips span
friends_multiautocomplete_tv.setText(ssb);
// move cursor to last
friends_multiautocomplete_tv
.setSelection(friends_multiautocomplete_tv.getText()
.length());
}
}
其實我只是在arraylist.When添加在編輯文字的名稱和ID的用戶刪除我想刪除其ID名稱。 – user1767260