2012-11-29 16 views
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); 
} 

即时寻找适当的语法,以获得这个填充列表的第一个位置的字符串,所以我可以把它放在一个干杯或保存到一个文件,即时新的在这个,如果我可以显示它在一个吐司我可以照顾其余的,谢谢如何敬酒在listview arrayadapter上的某个位置<string>?

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

回答

3

很简单:

String firstResult = matches.get(0); 
Toast.makeText(getContext(), firstResult, 
Toast.LENGTH_SHORT).show(); 
+0

感谢我总是四处找小时,然后我得到平原,这里简单 – JRowan

+0

很高兴我能HEL页。如果这是您的首选解决方案,请将答案标记为正确。 –

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"); 
      } 
     } 
    });