恢复隐藏按钮

时间:2018-02-04 21:52:19

标签: android

我有ImageButton ArrayList有9个按钮,onClick该按钮随setVisibility(View.GONE)消失,如何检测所有按钮何时被销毁并恢复?

    final ArrayList<ImageButton> bList  = new ArrayList<>();
    bList.add((ImageButton)findViewById(R.id.imageButton1));
    bList.add((ImageButton)findViewById(R.id.imageButton2));
    bList.add((ImageButton)findViewById(R.id.imageButton3));
    bList.add((ImageButton)findViewById(R.id.imageButton4));
    bList.add((ImageButton)findViewById(R.id.imageButton5));
    bList.add((ImageButton)findViewById(R.id.imageButton6));
    bList.add((ImageButton)findViewById(R.id.imageButton7));
    bList.add((ImageButton)findViewById(R.id.imageButton8));
    bList.add((ImageButton)findViewById(R.id.imageButton9));

    bList.get(0).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boxNum(0);
        }
    });
    bList.get(1).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boxNum(1);
        }
    });
    bList.get(2).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boxNum(2);
        }
    });
    // so on.. till num. 8

1 个答案:

答案 0 :(得分:1)

你可以有一个计数器变量,它计为9.九,它设置所有按钮setVisibility(View.VISIBLE)