Reddington91
Reddington91
采纳率0%
2017-05-06 02:18 阅读 1.1k

动态添加button后怎么控制

我设置了一个添加按钮和一个减少按钮但不知道怎么控制

 btn3.setOnClickListener(new OnClickListener(){//+
            public void onClick(View v){
                num+=1;
                Button btn5=new Button(function31.this);
                btn5.setText(String.valueOf(num));
                btn5.setId(num);
                l.addView(btn5);
                if(num!=0) {
                btn4.setVisibility(View.VISIBLE);
                cs.setVisibility(View.VISIBLE);
                dh.setVisibility(View.VISIBLE);
                hsds.setVisibility(View.VISIBLE);
                qsds.setVisibility(View.VISIBLE);
                btn1.setVisibility(View.VISIBLE);
                btn2.setVisibility(View.VISIBLE);
                gcc.setVisibility(View.VISIBLE);
                t1.setVisibility(View.VISIBLE);
                t2.setVisibility(View.VISIBLE);
                t3.setVisibility(View.VISIBLE);
                t4.setVisibility(View.VISIBLE);
                t5.setVisibility(View.VISIBLE);
                t6.setVisibility(View.VISIBLE);
                t7.setVisibility(View.VISIBLE);
                }
            }
        });

        btn4.setOnClickListener(new OnClickListener(){//+
            public void onClick(View v){
                    l.removeViewAt(num);
                    num-=1;
                    if(num==0){
                    btn4.setVisibility(View.INVISIBLE);
                    cs.setVisibility(View.INVISIBLE);
                    dh.setVisibility(View.INVISIBLE);
                    hsds.setVisibility(View.INVISIBLE);
                    qsds.setVisibility(View.INVISIBLE);
                    btn1.setVisibility(View.INVISIBLE);
                    btn2.setVisibility(View.INVISIBLE);
                    gcc.setVisibility(View.INVISIBLE);
                    t1.setVisibility(View.INVISIBLE);
                    t2.setVisibility(View.INVISIBLE);
                    t3.setVisibility(View.INVISIBLE);
                    t4.setVisibility(View.INVISIBLE);
                    t5.setVisibility(View.INVISIBLE);
                    t6.setVisibility(View.INVISIBLE);
                    t7.setVisibility(View.INVISIBLE);
                    }
            }
        });

不知道怎么控制新添加的button

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

5条回答 默认 最新

  • Reddington91 Reddington91 2017-05-06 02:35

    不知道怎么控制新添加的button

    点赞 评论 复制链接分享
  • zengxianzi 昭杏之念 2017-05-06 06:40

    把新建的button发在一个list里面:
    List btnList = new ArrayList<>();
    btnList.add(btn5);

    点赞 评论 复制链接分享
  • zengxianzi 昭杏之念 2017-05-06 06:41
    把新建的button发在一个list里面:
    List btnList = new ArrayList<>();
    btnList.add(btn5);
    
    点赞 评论 复制链接分享
  • zengxianzi 昭杏之念 2017-05-06 06:42
     把新建的button发在一个list里面:
    List<Button> btnList = new ArrayList<>();
    btnList.add(btn5);
    
    点赞 评论 复制链接分享
  • qq_36539304 接口的说法 2017-05-08 02:16

    应该可以考虑用循环控制,可以试试.........

    点赞 评论 复制链接分享

相关推荐