加载对话框,单击按钮时的进度对话框

问题描述 投票:0回答:1

嗨,我想在按钮执行任何其他操作之前先显示加载或进度对话框 1 秒......请帮忙

    button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

       <!-- want to a Show a Loading or Progress Dailog for 1 Second  -->

            if (isInternetPresent) {
                // Internet Connection is Present
            } else {
                // Internet connection is not present
                InternetNotContectedAlert();
            }
android progressdialog
1个回答
3
投票

你可以像下面这样做:

ProgressDialog csProgress = new ProgressDialog(NextActivity.this);
Button csButton = (Button) findViewById(R.id.buttonCs);
csButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        csProgress.setMessage("Loading...");
        csProgress.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                csProgress.dismiss();
                // whatever you want just you have to launch overhere.
            }
        }, 1000); // just specify the time when you want to launch your action 
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.