最近在用佳博的SDK做打印的功能,由于一直做的是.net,没有android的基础,这个功能我做了一个多月,包括前期调研佳博打印机的打印方式。佳博打印机有两种打印方式,一种是标签打印,要用到TscCommand这个接口;另外一种是票据打印,要用到EscCommand这个接口。由于没有android基础,不知道更新UI是需要放在UI线程里面,不能放在其他线程里面。这个问题我也弄了好久。不过现在已经解决了。这是更新UI的代码,以便以后方便查找。

// 构建Runnable对象,在runnable中更新界面
Runnable runnableUi = new Runnable() {
@Override
public void run() {
// 更新界面
GridView gview = (GridView) findViewById(R.id.gview);
ListView lview = (ListView) findViewById(R.id.lview);
TextView pchecked = (TextView) findViewById(R.id.p10);
TextView ptemperature = (TextView) findViewById(R.id.p9);
LinearLayout playout = (LinearLayout) findViewById(R.id.temperaturelayout);
CheckBox ck = (CheckBox) findViewById(R.id.pchecked);
Button btnspot = (Button) findViewById(R.id.btnspotmit); // 现货库
Button btnreceipt = (Button) findViewById(R.id.btnreceiptmit); // 补签收
Button btndelivery = (Button) findViewById(R.id.btndelivery); // 送货联
Button btnsubmit = (Button) findViewById(R.id.btnpsubmit);// 提交送货联
pchecked.setVisibility(TextView.GONE);
ptemperature.setVisibility(TextView.GONE);
playout.setVisibility(LinearLayout.GONE);
ck.setVisibility(CheckBox.GONE);
btndelivery.setVisibility(Button.GONE);
btnspot.setVisibility(Button.GONE);
btnreceipt.setVisibility(Button.GONE);
btnsubmit.setVisibility(Button.VISIBLE);
gview.setVisibility(GridView.GONE);
lview.setVisibility(ListView.VISIBLE);
SimpleAdapter adapter = new SimpleAdapter(PurchaseActivity.this,
maps, R.layout.listviewsource, new String[] { "pid",
"pcode", "punit" }, new int[] { R.id.p000,
R.id.p001, R.id.p003 });
lview.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
};

首先要在OnCreate方法里面声明一个专门用于更新UI的handler

Handler h=new Handler();

然后在需要用到的地方调用一下:

h.post(runnableUi);

我这边是在加入送货联的时候用到的这个:

// 加入送货联
btndelivery.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {

new Thread() {
public void run() {
clearCheck();
for (int i = 0; i < gv.getChildCount(); i++) {
View view = gv.getChildAt(i);
CheckBox checkBox = (CheckBox) ((ViewGroup) view)
.getChildAt(10);
if (checkBox.isChecked()) {
TextView pushid = (TextView) view
.findViewById(R.id.p00);
txtid = pushid.getText().toString();
Log.i("订单号", txtid);
ordlist.add(txtid);
strordid += txtid + ",";
}
}
if (ordlist.size() > 0) {
saveCheck("orderid", strordid);// 将选取的订单ID放入缓存中
InitLview();
h.post(runnableUi);
} else {
error_msg = "您还没有选取数据";
alertHandler.sendEmptyMessage(0);
}
}
}.start();
} catch (Exception e) {
e.printStackTrace();
}
}

});

 

最后贴上gprinter Android SDK:

http://pan.baidu.com/s/1bpjhD9t 这个是1.1版本的

http://pan.baidu.com/s/1hsIjybM 这个是2.1版本的