2010-02-13 5 views
3

간단한 시저 암호화 활동을 작성 중입니다. 화면에 두 개의 EditTexts, 한 개의 일반 텍스트, 한 개의 crypted 텍스트. 다음은 암호화 된 EditText의 예입니다. 일반 텍스트는 유사합니다. 일반 텍스트를 입력 할 때프로그래밍 방식으로 EditText 스크롤하기

<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" /> 

는 지금은 프로그래밍 방식 지하실 및 암호화 - 글고 것을 채우고 TextChangedListener 실행이있다. 여태까지는 그런대로 잘됐다.

입력 한 일반 텍스트가 너무 길어지면 일반 텍스트 EditText가 내 입력과 함께 스크롤되지만 암호화 편집 텍스트는 텍스트 상단에 그대로 있습니다. 나는 항상 내용의 최종선을 보여주기 위해 crypto-EditText를 스크롤하고 싶습니다.

어떻게해야할까요? onTextChanged() - TextWatcher의 메소드?

+0

흥미로운 질문을. 가능 *해야 할 것 같지만 문서를 뚫고 아무것도 찾지 못했습니다. –

답변

7

그것을 알았다. 그것은 커서 (EditText 및 TextViews에서 Selection이라고 함)였습니다.

이 내가이 일을하는 데 방법입니다

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

그런 다음 사용

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

휴가, 마침내 :) 항상 Spannable의 힘을 과소 평가)

+0

덕분에 많은 도움이되었습니다! – Chris623

0

기본 클래스 android.view.View에는 getScrollX(), getScrollY() 및 scrollTo() 메소드가 있습니다.

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

+0

나는 그것을 시험해 보았다. 내 cleartext-EditText의 getScrollY() - 값을 기록합니다. 텍스트를 입력 할 때이 값이 증가합니다. 그럼 난 scrollToY() 암호화 - EditText에서 시작에 대한 동일한 값입니다. 하지만 두 번째 EditText는 스크롤되지 않습니다. 나는 scrollTo()를 디버깅했지만 처음에 변경된 mScrollY- 변수는 다음에 scrollTo()를 호출 할 때까지 0으로 재설정됩니다. 나는 현재 커서 위치가 범인이라고 의심하고있다. 그걸 보면서. – rflexor

관련 문제