0
我想將條形碼掃描儀的結果上傳到編輯文本,但它不顯示在編輯文本中。我可以知道問題是什麼,我該如何解決?無法讀取條形碼掃描儀的輸出
這是我的代碼
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class ScannerActivity extends AppCompatActivity {
private ZXingScannerView scannerView;
private EditText ScanBarcode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner);
ScanBarcode = (EditText)findViewById(R.id.editscanbar);
}
public void scanCode(View view){
scannerView = new ZXingScannerView(this);
scannerView.setResultHandler(new ZXingScannerResultHandler());
setContentView(scannerView);
scannerView.startCamera();
}
@Override
public void onPause(){
super.onPause();
scannerView.stopCamera();
}
class ZXingScannerResultHandler implements ZXingScannerView.ResultHandler{
@Override
public void handleResult(Result result){
String resultCode = result.getText().toString();
ScanBarcode.setText(resultCode);
Toast.makeText(ScannerActivity.this, resultCode,
Toast.LENGTH_SHORT).show();
setContentView(R.layout.activity_scanner);
scannerView.stopCamera();
}
}
}
我已經改變了它,仍然沒有什麼顯示在編輯文本了
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class ScannerActivity extends AppCompatActivity implements
ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
private EditText ScanBarcode;
@Override
public void onCreate(Bundle State) {
super.onCreate(State);
mScannerView = new ZXingScannerView(this);
setContentView(R.layout.activity_scanner);
ScanBarcode = (EditText)findViewById(R.id.editscanbar);
}
public void scanCode(View view){
mScannerView.setResultHandler(this);
setContentView(mScannerView);
mScannerView.startCamera();
}
@Override
public void onResume(){
super.onResume();
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
@Override
public void onPause(){
super.onPause();
mScannerView.stopCamera();
}
@Override
public void handleResult(Result rawResult){
ScanBarcode.setText(rawResult.getText());
setContentView(R.layout.activity_scanner);
mScannerView.stopCamera();
}
}