Hello I am really new on android development and I would like to ask a simple question.
I have a button (buttonR2C1). When I click the buttonR2C1 I change the text of my textView (the textview is included inside a scrollView).The problem is that the position of the scrollView remains the same.
I would like to add an action that brings my ScrollView in position 0,0 by using the scrollTo action.
Can anyone help me achieve this?
.java
final TextView tv2 = (TextView) findViewById(R.id.mainL1R2);
final Button button1 = (Button) findViewById(R.id.buttonR2C1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
tv2.setText(getResources().getString(R.string.L1R2C1));
}
});
.xml
<Button
android:id="@+id/buttonR2C1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capitolo 1"
android:textSize="18sp" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical" >
<TextView
android:id="@+id/mainL1R2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:fontFamily="CustomText"
android:gravity="left"
android:scrollHorizontally="true"
android:text="@string/L1R2C1"
android:textSize="20sp"
android:textStyle="normal" />