如果有相同的值,请尝试检查两个值

时间:2017-05-20 23:27:40

标签: java android if-statement qr-code

我正在尝试检查值。我从QR码获得的第一个值,第二个是我添加到源代码中的String。对于使用ZXingScannerView库的QR功能。这是我的代码,但不幸的是,我总是要去其他地方。这是我的代码:

公共类Konto扩展了AppCompatActivity实现     ZXingScannerView.ResultHandler {

private SQLiteHandler db;
private SessionManager session;

private ZXingScannerView mScannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_konto
    );
    ImageButton test = (ImageButton) findViewById(R.id.testforsql);
    test.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mScannerView = new ZXingScannerView(Konto.this);
            setContentView(mScannerView);
            mScannerView.setResultHandler(Konto.this);
            mScannerView.startCamera();

        }
    });


    }

@Override
public void handleResult(Result result) {
    Log.w("handleResult",result.getText());
  /*  AlertDialog.Builder builder = new AlertDialog.Builder(Konto.this);
    builder.setTitle("Scan Result");
    builder.setMessage(result.getText());
    AlertDialog alertDialog = builder.create();
    alertDialog.show();*/
    if (result.equals("test")){
        Toast.makeText(getApplicationContext(),"works",Toast.LENGTH_LONG);
    }else {
        Toast.makeText(getApplicationContext(),"works not",Toast.LENGTH_LONG).show();
    }
    mScannerView.resumeCameraPreview(Konto.this);

}

}

1 个答案:

答案 0 :(得分:0)

不熟悉API,但您不需要致电

result.getText().equals 

而不是

result.equals