0
我想要和API來對斑馬打印機打印的門票,我有(只是用於測試),我的主要活動:獲取的EditText從活動中的Android
public class ZebraPrinterActivity extends Activity {
public EditText macAddress;
public Button testButton;
public Printer zebra;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
macAddress = (EditText) this.findViewById(R.id.editText1);
testButton = (Button) this.findViewById(R.id.button1);
zebra = new Printer(new ZebraPrinterActivity());
testButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
}
}).start();
}
});
}}
,我有我的課(API)稱爲打印機:
public class Printer {
private ZebraPrinterConnection zebraPrinterConnection;
private ZebraPrinter zebra;
private String MAC;
public Printer (Activity activity) {
zebraPrinterConnection = null;
zebra = null;
activity....get Edit Text
this.MAC = MAC;
}}
我需要的是從早期活動中獲取編輯文本,有沒有辦法做到這一點?
是的,但我需要在Printer類中做到這一點 –
你應該可以在Printer類中做到這一點(請參閱'活動'變量,而不是'this') – HXCaine
好的,你是對的,但有另一種方式嗎?我認爲這種方式不是最好的 –