当单击按钮删除时,android从arraylist中删除值

时间:2016-06-23 13:15:41

标签: java android arraylist

addberlian.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            // TODO Auto-generated method stub
            removebutir = new ArrayList<Button>();
            final LinearLayout newView1 = (LinearLayout) getActivity()
                    .getLayoutInflater().inflate(R.layout.rowberlian, null);
            newView1.setLayoutParams(new LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            butirberlian = (EditText) newView1.findViewById(R.id.butir);
            bntk = (EditText) newView1.findViewById(R.id.bentuk);
            karatberlian = (EditText) newView1.findViewById(R.id.totkarat); 
            btnRemoveberlian = (Button) newView1.findViewById(R.id.btnRemoveberlian);

            btnRemoveberlian.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                     butir1.remove(butirberlian);   
                     ly3.removeView(newView1);
                } 
            });

            ly3.addView(newView1);
            butir1.add(butirberlian);           
            removebutir.add(btnRemoveberlian);
        }
    });

for(int i = 0; i< butir1.size();i++){
            butir.add(butir1.get(i).getText().toString());          
            TextView tv = new TextView(getActivity());
             tv.setText(""+butir.get(i));
             lyy.addView(tv);

我有edittext表单和按钮删除,每次单击按钮添加时都会动态生成。 edittext的值存储在arraylist中。如果我点击按钮删除,将删除edittext表单。但是,即使删除了edittext,该值仍未删除。单击删除按钮后如何删除该值?

1 个答案:

答案 0 :(得分:0)

尝试使用删除按钮部分

View view = findViewById(R.id.button);
view.setVisibility(View.GONE);

和xml文件

<Button android:visibility="gone"/>