1. Check out our app, Forums for Android! Download and leave feedback here!

Dynamically inserting text into textview on cursor location?

Discussion in 'Application Development' started by AndyBoot, May 13, 2010.

  1. AndyBoot

    AndyBoot Member
    Thread Starter
    16

    May 13, 2010
    17
    2
    16
    Leeds, UK
    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! :)
     

    Advertisement

  2. AndyBoot

    AndyBoot Member
    Thread Starter
    16

    May 13, 2010
    17
    2
    16
    Leeds, UK
    Hi All,

    Managed to figure this out for myself:

    Code (Text):
    1.  
    2.         EditText vw = (EditText)findViewById(R.id.EditText01);
    3.         Editable str = vw.getText();
    4.         String text = "lalalalalalla";
    5.         int len = text.length();
    6.         str.insert(vw.getSelectionStart(), text, 0, len);
    7.  
    Regards,

    Andy
     

Share This Page

Loading...