1

当我跑步时

msgcheck.setOnClickListener(new View.OnClickListener() {            
        @Override
        public void onClick(View v) {

            if(msgcheck.isChecked()){
                //hedearMsg


                final Dialog dialog = new Dialog(this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
                dialog.setContentView(R.layout.custommsg);
                dialog.setCancelable(true);
                dialog.show();

                Thread t = new Thread() {
                  public void run() {
                     // Do something on another thread
                      PopulatePeopleList();

                  }
                };
                t.run();

        }
    });

我的程序挂了几秒钟,然后显示对话框
我想在不挂起的情况下运行这个对话框,并且 PopulatePeopleListfunc 工作有人知道吗?

4

2 回答 2

3

线程以 开头start,而不是run

Thread t = new Thread() {
    public void run() {
        // Do something on another thread
        PopulatePeopleList();
    }
};
t.start();

run只会run在主线程上按顺序调用该方法。

于 2012-10-28T18:20:03.443 回答
0

第三种选择是使用 a Runnable,它可以在线程内或其他地方构造:

new Thread(new Runnable()
{
    @Override
    public void run()
    {
        PopulatePeopleList();
    }

}).start();
于 2012-10-28T18:23:49.630 回答