2
     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));


    }



    super.onActivityResult(requestCode, resultCode, data);
}

我正在寻找正确的语法来将此填充列表的第一个位置转换为字符串,以便我可以将其放入 toast 或将其保存到文件中,我对此很陌生,如果我可以在 toast 上显示它,我可以照顾其余的,谢谢

Toast.makeText(this,(CharSequence) wordsList.getItemAtPosition(0) , Toast.LENGTH_LONG).show();
4

2 回答 2

3

挺容易:

String firstResult = matches.get(0);
Toast.makeText(getContext(), firstResult,
Toast.LENGTH_SHORT).show();
于 2012-11-29T06:51:49.413 回答
1
wordList.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int pos, long l) {
            try {
               Toast.makeText(this,"Position is===>>"+pos , Toast.LENGTH_LONG).show();
            }
            catch(Exception e) {
                System.out.println("Nay, cannot get the selected index");
            }
        }
    });
于 2012-11-29T06:59:18.157 回答