1. Download our Official Android App: Forums for Android!

Apps Dynamically inserting text into textview on cursor location?

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

  1. AndyBoot

    AndyBoot Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    17
    Joined:
    May 13, 2010

    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 Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    17
    Joined:
    May 13, 2010

    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...