0
在我的程序中,用戶單擊該按鈕,該按鈕會彈出一個提示用戶提示的內容。在用戶說出一個詞組或單詞後,會顯示列出的可能詞彙。我的問題是,如何選擇所選的值並將其用作程序中的變量。Android從語音到文本的數組中獲取價值
這是我的代碼:
public class MainActivity extends Activity {
Button listen;
ListView lv;
static final int check = 1111;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView)findViewById(R.id.listView1);
listen = (Button)findViewById(R.id.button2);
}
public void touched2(View v){
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.
LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak up!");
startActivityForResult(i, check);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == check && resultCode == RESULT_OK){
ArrayList results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
}
super.onActivityResult(requestCode, resultCode, data);
}
}
感謝您的幫助提前!
簡單地得到OnItemClickListener的列表視圖,並獲得選擇的項目.. :) –