1、首先建立一个printerInterface
public class passwordInterface extends Activity {
private ProgressDialog processDialog;
private EditText et;
private TextView text;
public void showResult(final String message) {
passwordInterface.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// show
Builder builder = new Builder(passwordInterface.this);
TextView tv = new TextView(passwordInterface.this);
tv.setTextSize(20);
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setText(message);
builder.setView(tv);
builder.setPositiveButton("确定", null);
builder.create().show();
}
});
}
public void showResult(final String title, final String message) {
passwordInterface.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// show
Builder builder = new Builder(passwordInterface.this);
TextView tv = new TextView(passwordInterface.this);
tv.setTextSize(20);
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setText(message);
builder.setTitle(title);
builder.setView(tv);
builder.setPositiveButton("确定", null);
builder.create().show();
}
});
}
public void showWait(final String message) {
passwordInterface.this.runOnUiThread(new Runnable() {
@Override
public void run() {
processDialog = new ProgressDialog(passwordInterface.this);
processDialog.setMessage(message);
processDialog.setIndeterminate(true);
processDialog.setCancelable(false);
processDialog.show();
}
});
}
public void waitClose() {
passwordInterface.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (processDialog!=null&&processDialog.isShowing()) {
processDialog.dismiss();
}
}
});
}
}
2、在按钮的方法里面,执行完打印之后,添加以下代码
showWait("正在打印");
Thread t = new Thread(run);
t.start();
3、然后完成run方法的定义
//@洋葱 等待加载
private Runnable run = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(600);
waitClose();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
注意,run方法定义为私有,放在内部类里面,打印方法的外面。