2012-11-29 59 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"); 
      } 
     } 
    });