• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Dynamically inserting text into textview on cursor location?

AndyBoot

Newbie
Hiya,

I'm trying to figure out how to insert preset text (via menu) into a textview textbox where the cursor is currently located.

In an ideal world if I intended to insert preset text to the very end of the textview content, I would just use the theory of textview.value + "preset text". But this is not what I require.

I would like to be able to click an area of the textview content and insert preset text between the start and end of the textbox, so where I place the cursor.

Anybody that can help me would be an absolute star!!!

Thanks in advance! :)
 
Hi All,

Managed to figure this out for myself:

Code:
    	EditText vw = (EditText)findViewById(R.id.EditText01);
        Editable str = vw.getText();
        String text = "lalalalalalla";
        int len = text.length();
        str.insert(vw.getSelectionStart(), text, 0, len);

Regards,

Andy
 
Back
Top Bottom