0

Im learning how to use the gesture builder to recognize gestures and use them in development.

This is a snippet of my code :

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    ArrayList<Prediction> predictions = oLib.recognize(gesture);
    // We want at least one prediction
    final EditText et_Text = (EditText) findViewById(R.id.editText1);
    if (predictions.size() > 0) {
        Prediction prediction = predictions.get(0); 
        if (prediction.score > 0.1) { // do the work
            //Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT)
                    //.show();
            String s ="o";
            if (prediction.name == s) {



                et_Text.setText("o");
                Toast.makeText(this, "TEST", Toast.LENGTH_SHORT)
                .show();
            }

        }

    }
}

I got a gesture called o and the idea is when i make that gesture it will type o in a EditText but i cant figure out why it dosent do just that ?

It recognizes the gesture in the first second if (score >0.1) but not in the one blow.

Any idea why ?

Dukes
  • 342
  • 1
  • 3
  • 14

1 Answers1

1

Do NOT compare Strings with ==; that is most likely your problem. To compare Strings, use the .equals() method., aka: if (s.equals(prediction.name))

In short, == compares references, whereas .equals() actually compares the the contents of the Strings. I would go into more detail, but it has been covered in many threads, for example.

Community
  • 1
  • 1
Steve P.
  • 14,489
  • 8
  • 42
  • 72