Arun Badole
Arun Badole

Reputation: 11097

Can I get the text at the time when user is selecting it in EditText from written text in Android?

I want to know that can I get the selected text by user at time when user is Selecting it from EditText.Is it possible to do it Please Help Me...

Upvotes: 0

Views: 107

Answers (1)

Robbin Poh
Robbin Poh

Reputation: 21

Create this file called SelectionListener.java package

robbin.android.NeedToWrite_Trial;
public interface SelectionListener
{
    public abstract void onSelectionChanged(myEditText et, int selStart, int selEnd);
}

Then in your main function, implement SelectionListener, then declare your variable

myEditText et;

And in your class myEditText, include this function:

@Override
public void onSelectionChanged (int selStart, int selEnd)
{
    super.onSelectionChanged (selStart, selEnd);
    if(selectionListener != null)
    {
        selectionListener.onSelectionChanged(this, selStart, selEnd);
    }
}

You then include this function in your main function:

public void onSelectionChanged (ScrollWrappedEditText et, int selStart, int selEnd)
{
    selectedtext=(""+getText()).substring(getSelectionStart(), getSelectionEnd());
}

Upvotes: 2

Related Questions