java - Android RECOGNIZE_SPEECH_ACTIVITY 对于问题(对于?)
问题描述
完成此方法后,我试图将字符串 (strSpeech2Text) 用字符制动,并将它们分别分配到 T1 T2 等文本视图中。
如果我不尝试重用 foreach,那么我得到的是整个单词被分配给每个文本视图。所以分配工作..
那有什么问题?
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RECOGNIZE_SPEECH_ACTIVITY:
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> speech = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String strSpeech2Text = speech.get(0);
grabar.setText(strSpeech2Text);
TextView T1;
T1 = (TextView) findViewById(R.id.TIRADA0);
TextView T2;
T2 = (TextView) findViewById(R.id.TIRADA1);
TextView T3;
T3 = (TextView) findViewById(R.id.TIRADA2);
TextView T4;
T4 = (TextView) findViewById(R.id.TIRADA3);
//String v;
String a = strSpeech2Text;
int n = 0;
for (TextView i : Arrays.asList(T1, T2, T3, T4)) {
Character v = a.charAt(n);
i.setText(Character.toString(v));
n++;
}
}
break;
default:
break;
}
}
解决方案
试试这个。我没有测试它,但它对我来说看起来不错:
ArrayList<TextView> textViews = Arrays.asList(T1, T2, T3, T4);
for (int i=0; i<textViews.size() && strSpeech2Text.length>i; i++) {
textViews.get(i).setText(strSpeech2Text.substring(i,i+1));
}
推荐阅读
- python - 将 Eye Gaze(俯仰和偏航)转换为屏幕坐标(人在看哪里?)
- vue.js - Vue 组件错误:属性或方法 X 未在实例上定义,但在渲染期间引用
- r - R文本挖掘——去除特殊字符和引号
- azure-devops - 在 VSTS / Azure DevOps 中重置分支更新的构建策略
- multithreading - 使用 DatagramSocket Android 的线程运行方法和处理程序
- batch-file - 需要批处理命令获取 mac 地址并比较 txt 文件吗?
- vba - 显示访问报告列表框一个字段分为 3 列
- orchardcms - Pluralsight Advanced - 电影内容未显示在内容表中
- c - “ssize_t wb;”中变量名的命名约定
- mysql - 闭表插入查询