mercredi 1 mars 2017

Retrieving string for if/else clause in android studio

im trying to get a qr code scanner going where it should redirect to different activities in dependancy on the code scanned but im having trouble getting the string from the result in the correct form, thanks in advance

  @Override
public void handleResult(Result result) {
    Log.w("handleResult", result.getText());
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Scan results");
    builder.setMessage(result.getText());
    AlertDialog alertDialog = builder.create();
    alertDialog.show();

    String id_helper = result.getText().toString();

    if (id_helper == "1") {
       startActivity(new Intent(this, Sample1.class));
    } else if (id_helper == "2") {
        startActivity(new Intent(this, Sample2.class));
    } else {
        startActivity(new Intent(this, Sample3.class));
    }

Aucun commentaire:

Enregistrer un commentaire