Android 语音转文字:光标到行尾
Android Voice to text: cursor to end of the line
在Android中使用语音发短信时,如何让光标移动到行尾。此外,当第二次按下 VTT 时,我的语音转文本会将现有文本替换为新文本。
textViewResult = (TextView) findViewById(R.id.spoken_text);
if (resultCode == RESULT_OK && data != null){
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
textViewResult.setText(result.get(0));
textViewResult.setText(result.get(1));
}
要将光标移动到行尾(我假设您正在谈论 EditText 元素),您可以
EditText voiceText = (EditText) findViewById(R.id.your_id);
voiceText.setSelection(voiceText.getText().length());
关于如何更新而不是替换文本,需要有关如何存储文本等的更多信息。
一个建议是查看类似 this 的博文,其中展示了如何使用 android 架构组件进行语音转文本。
在Android中使用语音发短信时,如何让光标移动到行尾。此外,当第二次按下 VTT 时,我的语音转文本会将现有文本替换为新文本。
textViewResult = (TextView) findViewById(R.id.spoken_text);
if (resultCode == RESULT_OK && data != null){
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
textViewResult.setText(result.get(0));
textViewResult.setText(result.get(1));
}
要将光标移动到行尾(我假设您正在谈论 EditText 元素),您可以
EditText voiceText = (EditText) findViewById(R.id.your_id);
voiceText.setSelection(voiceText.getText().length());
关于如何更新而不是替换文本,需要有关如何存储文本等的更多信息。
一个建议是查看类似 this 的博文,其中展示了如何使用 android 架构组件进行语音转文本。