久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在編輯文本中獲取 Android 中的光標位置?

Get Cursor Position in Android in Edit Text?(在編輯文本中獲取 Android 中的光標位置?)
本文介紹了在編輯文本中獲取 Android 中的光標位置?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用自定義的 EditText 視圖.我已經覆蓋了 OnKeyUp 事件并且能夠捕獲 Enter 按鍵.現在我的要求是,當用戶輸入文本嗨.你好嗎?"然后將光標保持在單詞are"之后并按Enter,我需要獲取光標位置,以便在按下Enter鍵時提取光標后的文本.請讓我知道如何做到這一點.感謝您的時間和幫助.

I am using a custom EditText View. I have overridden the OnKeyUp event and am able to capture the Enter Key press. Now my requirement is, when the user has entered a text "Hi. How are you?" and then keeps the cursor after the word "are" and press enter, I need to get the cursor location so that i can extract the text after the cursor at the moment the Enter Key was pressed. Please let me know how to do this. Thank you for your time and help.

推薦答案

您可以使用 getSelectionStart() 和 getSelectionEnd() 方法獲取光標位置.如果沒有突出顯示文本,getSelectionStart() 和 getSelectionEnd() 都會返回光標的位置.所以這樣的事情應該可以解決問題:

You can get the Cursor position using the getSelectionStart() and getSelectionEnd() methods. If no text is highlighted, both getSelectionStart() and getSelectionEnd() return the position of the cursor. So something like this should do the trick:

myEditText.getSelectionStart();

myEditText.getSelectionEnd();

如果你想選擇光標后的所有文本,你可以使用這個:

Then if you want to select all the text after the cursor you could use this:

int cursorPosition = myEditText.getSelectionStart();
CharSequence enteredText = myEditText.getText().toString();
CharSequence cursorToEnd = enteredText.subSequence(cursorPosition, enteredText.length());

這篇關于在編輯文本中獲取 Android 中的光標位置?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: 国产精品污www一区二区三区 | 国产精品1区2区3区 一区中文字幕 | 亚洲视频免费在线 | 亚洲综合婷婷 | 欧美综合久久 | 欧美99 | 国产精品国产 | 91久久精品视频 | 日本不卡一区二区三区在线观看 | 亚洲一区二区三区视频免费观看 | 91精品国产综合久久久久蜜臀 | 亚洲视频中文字幕 | 色综合久久久久 | 久久99精品久久久久久秒播九色 | 二区在线视频 | 福利视频日韩 | 在线视频 亚洲 | 天天综合亚洲 | 日韩欧美成人一区二区三区 | 国产一区二区 | 日韩一区二区三区在线视频 | 日韩欧美中文在线 | 欧美一区二区三区久久精品 | 国产精品久久久久久久毛片 | 老司机67194精品线观看 | 国产精品久久久久久久久久久久午夜片 | 黄色小视频大全 | 国产精品久久亚洲 | 99精品国自产在线观看 | 亚洲一区二区三区桃乃木香奈 | 欧美日韩在线看 | 在线播放中文字幕 | 亚洲精品一二区 | 欧美一级二级视频 | 国产精品视频播放 | 中文字幕动漫成人 | 2019精品手机国产品在线 | 黑人巨大精品 | 欧洲视频一区 | 成人在线免费av | 在线观看亚洲精品 |