当我运行时
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 工作有人知道吗?
最佳答案
线程以start
开始,而不是run
:
Thread t = new Thread() {
public void run() {
// Do something on another thread
PopulatePeopleList();
}
};
t.start();
run
只会在主线程上顺序调用 run
方法。
关于java - 我想在不挂起程序的情况下运行一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13111594/