Search code examples
androidtextcursorvoice-recognition

Android Voice to text: cursor to end of the line


When using the voice to text in Android, how do you make the cursor go to the end of the line. Also, My voice to text replaces existing text with new text when the VTT is pressed a second time.

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));
            }

Solution

  • To move the cursor to the end of the line (I assume you are talking about an EditText element) you can do

    EditText voiceText = (EditText) findViewById(R.id.your_id); 
    voiceText.setSelection(voiceText.getText().length());
    

    Regarding how to update your text instead of replacing it requires more info about how you store the text and such.

    One recommendation could be to look at something like this blogpost, showcasing how to do voice to text with android architecture components.