Programmatically scrolling an EditText

↘锁芯ラ 提交于 2019-12-01 18:54:10

Ok, found it. It was the cursor (called Selection on EditText and TextViews).

This is how I got it to work:

ivClear    // assigned the EditText that has the input
ivCrypt    // assigned the target EditText, that I want to scroll
aText      // the input from ivClear, crypted

Then use:

    ivCrypt.setText(aText);                               // assign the Text
    ivCrypt.setSelection(ivClear.getSelectionStart());    // scroll

Phew, finally :) Always underestimated the power of the Spannable ;)

The base class android.view.View has methods getScrollX(), getScrollY() and scrollTo() that may be helpful, though I haven't tried it.

http://developer.android.com/reference/android/view/View.html#scrollTo(int, int)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!