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
setSelection(int index)
method inEdittext
should allow you to do this.There is only one position in an empty EditText, it's
setSeletion(0)
.Or did you mean you want to get focus to your
EditText
when your activity opens? In that case itsrequestFocus()
If you want to place the cursor in a certain position on an EditText, you can use:
Additionally, there is the possibility to set the initial and final position, so that you programmatically select some text, this way:
Please note that setting the selection might be tricky since you can place the cursor before or after a character, the image below explains how to index works in this case:
So, if you want the cursor at the end of the text, just set it to
yourEditText.length()
.as a reminder: if you are using
edittext.setSelection()
to set the cursor, and it is NOT working while setting up analertdialog
for example, make sure to set theselection()
AFTER the dialog has been createdexample:
In Xml file android:paddingLeft:
i hope this help you
Where position is an int: