我只需要顯示Arraylist
中的第一個條目。如何從arraylist中獲取第一個數據(在我的代碼中匹配)
我下面的代碼顯示了所有的結果,但我只需要列表中的第一個條目。
wordsList
是ListView
名稱:
ArrayList <<String>> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,matches));
全部方法代碼:
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)));
}
}
「第一數據」是什麼意思?你是指「ArrayList」的第一個元素嗎? – minhaz1 2012-08-08 19:39:52
根據user1543340在第一條語句中提出的問題,這是一個問題。但是,user1543340提到了'ListView',這讓我稍微感到厭倦。 – prolink007 2012-08-08 19:41:25
錯誤是「構造函數ArrayAdapter(VoiceRecognitionDemo,int,String)未定義」 –
user1543340
2012-08-08 19:52:24