• ProcessOnLoading


    =========================================

    3.18程序加载中,请稍候

    ProgressDialog与线程整合使用.

    效果图:

     

     

    代码:

    package edu.cqutzx.ProgramOnloading;

     

    import android.app.Activity;

    import android.app.ProgressDialog;

    import android.os.Bundle;

    import android.view.View;

    import android.widget.Button;

    import android.widget.TextView;

     

    publicclass ProgramOnLoadingActivity extends Activity {

        private Button btn;

        private TextView tv;

        public ProgressDialog pd = null;

        /** Called when the activity is first created. */

        @Override

        publicvoid onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

           

            /* Find the object by ID.*/

            btn = (Button) findViewById(R.id.btn);

            tv = (TextView) findViewById(R.id.tv);

           

            /* Add a listener to the Button (btn) */

            btn.setOnClickListener(new Button.OnClickListener ()

            {

               @Override

               publicvoid onClick(View v)

               {

                  /* Find the Strings in file strings.xml */

                  final CharSequence strDialogTitle = getString(R.string.strDialogTitle);

                  final CharSequence strDialogBody = getString(R.string.strDialogBody);

                 

                  /*Show Progreess Dialog. */       

                  /*It's ok to write like this :*/

                pd = ProgressDialog.show(ProgramOnLoadingActivity.this,strDialogTitle, strDialogBody);

               //pd = ProgressDialog.show(ProgramOnLoadingActivity.this,strDialogTitle, strDialogBody,true);

               tv.setText(strDialogBody);

              

               new Thread()

               {

                  @Override

                  publicvoid run() {

                      try

                      {

                        

                         //System.out.println("aaaaaa");

                         sleep(10000);

                         //System.out.println("bbbbbb");

                         //Toast.makeText(getBaseContext(), strDialogBody, Toast.LENGTH_LONG).show();

                         //System.out.println("ccccc");

                      }

                      catch(Exception e)

                      {

                         e.printStackTrace();

                      }

                      finally

                      {

                         /* Let the dialog disappear .*/

                         pd.dismiss();

                        

                         /*Mobile tv had used this method: when EIXT the program, show a Dialog first

                          * and then kill the progrom.*/

                         //finish();

                      }

                  }

                 

               }.start();

               }       

            }

            );

           

        }

    }

    问题:

    Can't create handler inside thread that has not called Looper.prepare()

    解决办法:

    http://mycoding.iteye.com/blog/882756

    总结:线程的使用

    new Thread()

    {

             Public void run()

    {

             Tasktodo();

    }

    }

  • 相关阅读:
    oracle中文显示为问号
    oracle 11g 安装报错(agent_nmhs)
    yum源配置
    ora-00020
    mysql停止正在执行的SQL语句
    linux root用户被锁定
    MySQL8.0 根据ibd文件恢复表结构
    mysql 8.x 开启远程访问和修改root密码、
    个人博客迁移到github
    postman断言方式
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2635477.html
Copyright © 2020-2023  润新知