Okay well I apologize for how sloppy this code is, but I still cant figure out how to post a code tag on here correctly. So I am making an Android application (Java) and i have a scrolling text field. If the user scrolls a long row down and stays at the end when they click the next row and if it is short, it will be scrolled down on that element too even though it may be a 1 line(and non scrollable) row. I was wondering if there is any way I can call something to right after txtLvlInfo.setText to reset the x-scroll value to 0 or something so it is always reset to 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>
A tip for putting code in, just paste the code into the window, select it, and hit Ctrl(Cmd)+K. This will indent everything 4 spaces, and color and format your code.
In regards to your question, where is this switch statement located?
TextView does have a method inherited from View that you could use, called scrollTo(int, int)
, and just set to 0, 0, but I'm a little confused on what exactly you're doing. What are these TextViews' parent layouts? You could possibly just wrap the first TextView in a ScrollView, instead of doing setMovementMethod()
(which I'm personally unfamiliar with).
You can put your textview in a ScrollView in your XML layout and then reset scroll to top position by the following code:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) ((ScrollView) findViewById(R.id.myscrollView)).smoothScrollTo(0, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With