2

在此处输入图像描述 我有一个EditText.ImageView Plus

  1. 单击ImageView Plus 我正在用EditText 和膨胀新布局ImageView 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);
            }
        });
    }
    
4

1 回答 1

1

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

@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;
    }

}

希望这对您有所帮助并享受您的工作。

于 2013-05-20T07:14:23.927 回答