Reputation: 91
I have a speech recognition program that displays 5-6 results. I only want the 1st result to appear. Can you help with this please?
code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == check && resultCode == RESULT_OK){
ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results));
}
Please advise?
Thank you. FlinxSYS
Upvotes: 0
Views: 390
Reputation: 12537
There is a flag called RecognizerIntent.EXTRA_MAX_RESULTS
. You have to do this before the startActivityForResult
-call I guess (from the voice recognition example):
// Specify how many results you want to receive. The results will be sorted
// where the first result is the one with higher confidence.
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
// ...
startActivityForResult(intent,0);
Upvotes: 1
Reputation: 62459
You could have a flag indicating that a result was already found:
private boolean flag = false;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (!flag && requestCode == check && resultCode == RESULT_OK){
ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results));
flag = true;
}
Once the flag is set to true at the first found result, the if condition will be false for any other execution of the handler.
Upvotes: 0