Dynamically inserting text into textview on cursor location?


Last Updated:

  1. AndyBoot

    AndyBoot Member This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    17
    Likes Received:
    2
    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 This Topic's Starter

    Joined:
    May 13, 2010
    Messages:
    17
    Likes Received:
    2
    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...