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 sel开发者_StackOverflow中文版ected text by user at time when user is Selecting it from EditText.Is it possible to do it Please Help Me...
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());
}
精彩评论