按下按钮后如何立即设置可见性

时间:2017-04-08 14:06:45

标签: android progress-bar

我想在按下按钮后立即运行进度条。 当进度条开始显示所有内容后,按钮触发完成。

public void onClick(View view) {
    if (view == etLocation){
        etLocation.setText("");

    }
    if (view == btnGo){
        runOnUiThread(new Runnable(){
            @Override
            public void run() {
                progressBar.setVisibility(View.VISIBLE);
            } });

        Thread buttonpress = new Thread(new Runnable() {
            public void run()
            {
                buttonGo();
            }
        });

        buttonpress.run();
        try {
            buttonpress.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
    if (view == datePicker){
        new DatePickerDialog(MainActivity.this, date, myCalendar
                .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                myCalendar.get(Calendar.DAY_OF_MONTH)).show();
    }
}

进度条的可见性从一开始就设置为INVISIBLE。

1 个答案:

答案 0 :(得分:0)

试试这个:

    public void onClick(View view) {
    if (view == etLocation){
        etLocation.setText("");

    }
    if (view == btnGo){
progressBar.setVisibility(View.VISIBLE);
        runOnUiThread(new Runnable(){
            @Override
            public void run() {

            } });

        Thread buttonpress = new Thread(new Runnable() {
            public void run()
            {
                buttonGo();
            }
        });

        buttonpress.run();
        try {
            buttonpress.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
    if (view == datePicker){
        new DatePickerDialog(MainActivity.this, date, myCalendar
                .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                myCalendar.get(Calendar.DAY_OF_MONTH)).show();
    }
}