大家好我正在制作像扫描条形码和二维码一样的android项目,我完成了扫描部分,任何人都可以告诉我如何在出现结果对话后将结果存储在文本视图中。 谢谢 这是我的代码:
public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
Button scan_code;
private static final int CAMERA_REQUEST = 1888;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scan_code = (Button) findViewById(R.id.button);
}
public void QrScanner(View view){
mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView);
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera
}
@Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
@Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.e("handler", rawResult.getText()); // Prints scan results
Log.e("handler", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode)
// show the scanner result into dialog box.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Scan Result");
builder.setMessage(rawResult.getText());
AlertDialog alert1 = builder.create();
alert1.show();
// If you would like to resume scanning, call this method below:
// mScannerView.resumeCameraPreview(this);
}}
答案 0 :(得分:0)
试试这个,
在MainActivity.java
添加
TextView scanResult = (TextView)findViewById(R.id.txtScanResult);
在handleResult
scanResult.setText(rawResult.getText().toString);