Software Scroll EditText

I am writing a simple cache-encryption operation. Two EditTexts on the screen, one clear text, one encrypted. Here's an example for an encrypted EditText - plain text is similar.

<EditText android:layout_below="@id/Caesar_Label_CryptText" android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/Caesar_Text_CryptText" android:hint="Enter crypted text" android:maxLines="2" android:lines="2" android:minLines="2" android:inputType="text|textMultiLine|textVisiblePassword" android:scrollbars="vertical" android:gravity="top" /> 

Now, when entering plain text, I have TextChangedListener working, which programmatically encrypts and populates this crypto-EditText. So far so good.

When the entered text is completely long, scartext-EditText scrolls with my imputation, but the crypto-EditText remains at the top of the text. I would really like the crypto-EditText to scroll so that it always shows the bottom line of its contents.

How can this be done, preferably from the onTextChanged () method of TextWatcher?

+3
source share
2 answers

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

Here's how I earned it:

 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 Spannable;)

+7
source

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

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

0
source

Source: https://habr.com/ru/post/1341093/


All Articles