【问题标题】:android remove value from arraylist when button delete is clicked当单击按钮删除时,android从arraylist中删除值
【发布时间】:2016-06-23 13:15:41
【问题描述】:
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,该值仍然没有被删除。单击删除按钮后如何删除值?

【问题讨论】:

  • 对不起,我没有得到你的主要问题。该值仍未从 xmlview 或 arraylist 中删除?
  • arraylist.. 实际上我已经使用“删除”语法进行了测试,但只有最后一个被删除的值。不是我选择的那个。
  • 这是在 LinearLayout 还是 ListView 中?
  • 我使用线性布局来制作动态编辑文本和删除按钮

标签: java android arraylist


【解决方案1】:

试试这个删除按钮部分

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

和xml文件

<Button android:visibility="gone"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多