I need to show only the first entry from Arraylist.
My code below shows all the results but I need only the first entry from the list.
wordsList is the name of ListView:
ArrayList <<String>> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,matches));
Full method code:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
{
// Populate the wordsList with the String values the recognition engine thought it heard
ArrayList<String> matches = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS);
wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches.get(0)));
}
}
Since you are only wanting the first element from the
ArrayList<String> matchesthen you just need to create a newList<String>and add the first element to the newList.Then use that new
Listfor theAdapter.