本文介紹了Android - 從 EditText 中選擇文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我正在嘗試實現復制/粘貼功能.如何從 EditText 中選擇文本?
I'm trying to implement a copy/paste function. How can I get a selection of text from an EditText?
EditText et=(EditText)findViewById(R.id.title);
blabla onclicklistener on a button:
blabla onclicklistener on a button:
int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();
那我就卡住了.有什么想法嗎?
Then I'm stuck. Any ideas?
推薦答案
看起來你已經完成了找到所選區域的困難部分.現在你只需要從全文中提取那個子字符串.
Seems like you've already done the hard part by finding what the selected area is. Now you just need to pull that substring out of the full text.
試試這個:
String selectedText = et.getText().substring(startSelection, endSelection);
這只是一個基本的 Java 字符串 操作.
It's just a basic Java String operation.
這篇關于Android - 從 EditText 中選擇文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!