开发者

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

开发者 https://www.devze.com 2023-03-14 09:29 出处:网络
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 Selec

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());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消