简体   繁体   中英

Loading Dialog, Progress Dialog on Button Click

Hi i want to show a loading or progress dialog first for 1 second before button do anything else.... please help

    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();
            }

Just do it like this,it will work.

    ProgressDialog csprogress=new ProgressDialog(NextActivity.this);
        Button csButton=(Button)findViewById(R.id.txtx);
        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 mention the time when you want to launch your action 

            }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM