[英]android Listview onItemClick fill EditText
I'm working on a small program to text voice recognition, the issue is that the voice recognition is filling a listView, which is good, now i want to fill an EditText with the contents of the clicked ListView item: my code: 我正在开发一个用于文本语音识别的小程序,问题是语音识别正在填充listView,这很好,现在我想用单击的ListView项目的内容填充EditText:我的代码:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE)
if(resultCode == RESULT_OK) {
ArrayList<String> textMatchList = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (!textMatchList.isEmpty()) {
mlvTextMatches.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
textMatchList));
}
}
mlvTextMatches.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
//Not Sure what to do here!
EditText InputText = (EditText) findViewById(R.id.inptWord);
}
});
super.onActivityResult(requestCode, resultCode, data);
}`
Any ideas? 有任何想法吗?
Make textMatchList
a member variable: 使textMatchList
成为成员变量:
ArrayList<String> textMatchList = new ArrayList<String>();
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE)
if(resultCode == RESULT_OK) {
textMatchList = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
...
...
mlvTextMatches.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
EditText InputText = (EditText) findViewById(R.id.inptWord);
InputText.setText(textMatchList.get(position));
}
});
}
The position
parameter of the onItemClick
method represents the position of the clicked list item. onItemClick
方法的position
参数表示单击的列表项的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.