Reputation: 395
I'm building an app using speech recognition.. I'm storing the last sentence in a string from the textView and trying to compare it with the new word spoken like, when the User say "remove" the last word from the string in the text View should be removed..
I don't know what is wrong with this code ..
if(requestCode == request_code && resultCode == RESULT_OK)
{
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if(matches != null && matches.size() > 0)
{
text = matches.get(0);
if(text == "hello")
{
text = (String) et.getText();
rep = text.replaceAll("\\d+\\Z", "");
Log.d(tag, "THis is not working");
et.setText(rep);
rep = null;
}
else
{
option = matches.get(0);
et.setText(option);
}
}
Thanks in Advance :D
Upvotes: 3
Views: 600
Reputation: 10136
Use if(text.equals("hello"))
instead of if(text == "hello")
or perhaps even better: if(text.equalsIgnoreCase("hello"))
remove last word from a text area:
String text = textArea.getText();
// capture everything except the last word into group 1
Pattern regex = Pattern.compile("(.*?)\\w+\\s*\\Z", Pattern.DOTALL);
Matcher matcher = regex.matcher(text);
if (matcher.find()) {
text = matcher.group(1);
textArea.setText(text);
}
Upvotes: 2