Reset TextView scroll up

Well, I apologize for how messy this code is, but I still can't figure out how to put the code correctly. So I am making an application for Android (Java) and I have a scrollable text box. If the user scrolls a long line down and remains at the end when they click on the next line, and if it is short, it will scroll on this element, even if it can be a line with 1 line (and without scrolling). I was wondering if there is a way in which I can call something immediately after txtLvlInfo.setText to reset the x-scroll value to 0 or something such that it always reset at the top of the content, long or short. Thanks for any help with this and please let me know if I need to clarify more.

TextView txtLvlInfo = (TextView) findViewById(R.id.txtLevelInfo); txtLvlInfo.setMovementMethod(new ScrollingMovementMethod()); switch (v.getId()){ case R.id.row1: txtLvlInfo.setText("1: My text view is only two lines max and so I set it to scroll, if the user clicks row2 to load that text while having me scrolled down they have to click and pull to drag back down to the top of text view 2 row."); break; case R.id.row2: txtLvlInfo.setText("I only fill line 1 of the two."); break; } 

_

 <TextView android:textColor="#052027" android:text="" android:id="@+id/txtLevelInfo" android:scrollbars="vertical" android:layout_alignParentLeft="true" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_toRightOf="@+id/minimizeBtn" android:layout_marginRight="38dip"> </TextView> 
+7
source share
2 answers

Tip for entering the code, just paste the code into the window, select it and press Ctrl (Cmd) + K. This will cause only 4 spaces to recede, as well as the color and formatting of your code.

As for your question, where is this switch statement located?

TextView has a method inherited from View that you can use called scrollTo(int, int) and just set it to 0, but I am "I'm a little confused about what exactly you are doing. What are the parent layouts of the TextViews? You could would just wrap the first TextView in a ScrollView instead of doing setMovementMethod() (which I personally am not familiar with).

+20
source

You can put your text image in ScrollView into your XML layout, and then reset to move to the top position with the following code:

  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) ((ScrollView) findViewById(R.id.myscrollView)).smoothScrollTo(0, 0); 
+1
source

All Articles