There are two EditText
,while loading the page a text is set in the first EditText, So now cursor will be in the starting place of EditText
, I want to set cursor position in the second EditText which contains no data. How to do this?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I have done this way to set cursor position to end of the text after updating the text of EditText programmatically here,
etmsg
is EditTextSet cursor to a row and column
You can use the following code to get the position in your EditText that corresponds to a certain row and column. You can then use
editText.setSelection(getIndexFromPos(row, column))
to set the cursor position. The following calls to the method can be made:getIndexFromPos(x, y)
Go to the column y of line xgetIndexFromPos(x, -1)
Go to the last column of line xgetIndexFromPos(-1, y)
Go to the column y of last linegetIndexFromPos(-1, -1)
Go to the last column of the last lineAll line and column bounds are handled; Entering a column greater than the line's length will return position at the last column of the line. Entering a line greater than the EditText's line count will go to the last line. It should be reliable enough as it was heavily tested.
The question was already answered but I thought someone could want to do that instead.
It works by looping through each character, incrementing the line count every time it finds a line separator. When the line count equals the desired line, it returns the current index + the column, or the line end index if column is out of bounds. You can also reuse the
getTrueLineCount()
method, it returns a line count ignoring text wrapping, unlikeTextView.getLineCount()
.This code will help you to show your cursor at the last position of editing text.
How to Set EditText Cursor position in Android
Below Code is Set cursor to Starting in
EditText
:Below Code is Set cursor to end of the
EditText
:Below Code is Set cursor after some 2th Character position :
In kotlin, you could create an extension function like this:
and then simply call
myEditText.placeCursorAtLast()