gpt4 book ai didi

android - 不删除 Arraylist 中的特定项目

转载 作者:行者123 更新时间:2023-11-29 01:53:25 27 4
gpt4 key购买 nike

enter image description here 我有一个 EditTextImageView Plus

  1. 单击 ImageView Plus 时,我正在使用 EditTextImageView Minus 扩充新布局。

  2. 现在,点击 ImageView Minus。我想删除膨胀的布局。如何做到这一点?

    ArrayList<View> viewList;
    /* Inflating new Layout */
    case R.id.ivPlus:
    LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    addView = layoutInflater.inflate(R.layout.add_edit, null);
    viewList.add(addView);
    ll.addView(addView);
    break;
    /* Removing the inflated layout */
    for (int i = 0; i < viewList.size(); i++) {
    final int j = i;
    ImageView minus= (ImageView ) viewList.get(j).findViewById(R.id.ivMinus);
    minus.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {

    LinearLayout extra_add = (LinearLayout) findViewById(R.id.lin_add);

    extra_add.removeViewAt(j);
    }
    });
    }

最佳答案

试试这个,只需像这样替换你的方法并享受

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_add:
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View addView = layoutInflater
.inflate(R.layout.inflate_layout, null);
viewList.add(addView);
lin_layout.addView(addView);
Button remove = (Button) addView.findViewById(R.id.button_remove);
remove.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
lin_layout.removeView((View) v.getParent());
viewList.remove((View) v.getParent());
}
});
break;
}

}

希望这对您有所帮助,祝您工作愉快。

关于android - 不删除 Arraylist 中的特定项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16644286/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com