0
我使用FlowLayout。外面我有這麼一個button。以編程方式從自定義佈局中刪除ImageView
按下在佈局中按鈕將相同的畫面多次按下按鈕。我想出瞭如何添加圖片,但如何刪除圖片?
numberButton.setOnValueChangeListener(new ElegantNumberButton.OnValueChangeListener() {
@Override
public void onValueChange(ElegantNumberButton view, int oldValue, int newValue) {
// Добавляем новый ImageView
if (oldValue < newValue) {
ImageView imageView = new ImageView(CreateNewTripActivity.this);
imageView.setImageResource(R.drawable.i_travel_logo_1);
ViewGroup.LayoutParams imageViewLayoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
imageViewLayoutParams.height = 300;
imageViewLayoutParams.width = 300;
imageView.setLayoutParams(imageViewLayoutParams);
imageView.setId();
flowLayout.addView(imageView);
} else {
//Удаляем
AlertDialog.Builder ad = new AlertDialog.Builder(CreateNewTripActivity.this);
ad.setTitle(getResources().getString(R.string.title_delete_person)); // заголовок
ad.setMessage(getResources().getString(R.string.dialog_aushure)); // сообщение
ad.setPositiveButton(getResources().getString(R.string.button_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int arg1) {
Toast.makeText(CreateNewTripActivity.this, "Вы сделали правильный выбор",
Toast.LENGTH_LONG).show();
//TO DO.......
flowLayout.removeView(imageView);
}
});
ad.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
Toast.makeText(CreateNewTripActivity.this, "Возможно вы правы", Toast.LENGTH_LONG)
.show();
}
});
ad.setCancelable(false);
}
}
});
可以被添加到每個imageview的唯一ID?類似的東西? //我讀了關於GONE選項。我想刪除所有相同的內容,而不是隱藏外觀。 –
除了GONE選項,你有沒有嘗試做imageView = null並通過System.gc()調用GC;你可以讓imageView成爲一個弱引用對象。 –