Ok, the code is fine. It scrolls to the current (x,y) position of your "scrollView" as says:
http://developer.android.com/reference/android/widget/ScrollView.html#scrollTo(int, int)
So I think that is an interpretation trouble. Is not the same a "line" on the textView that a "y" coordinate on the ScrollView. So if you want to get the row number 15 for example, "go variable" cant be 15, it should be something proportional to the "TextSize" + padding + margin, etc...
Do you know what I mean?
Hope it helps.
EDIT:: Here is a test that I tried and it work fine if you know which is the row that you want. Maybe the trouble is that you didn't calculate the line properly
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
public class MainActivity extends Activity {
ScrollView scroll;
TextView text;
EditText editText;
Button but;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView) findViewById(R.id.text);
scroll = (ScrollView) findViewById(R.id.scroll);
but = (Button) findViewById(R.id.button1);
editText = (EditText) findViewById(R.id.editText1);
but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int go = Integer.valueOf(editText.getText().toString());
makeScroll(go);
}
});
}
private void makeScroll(final int go) {
scroll.post(new Runnable() {
public void run() {
scroll.scrollTo(0, go * text.getLineHeight());
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and the xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="handleClick"
android:orientation="vertical"
tools:context=".PlayActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="sdqwerhdf adf qwer hdfashdf aE HFASDJFH ASKDFH QWLIULER HASDLIDLF HASDKJFH SDJF HAWEUJRH AS DKJFHL AWIUE4R YAS DJHFWIERUHF AUDF JHAWHWER ASJDFH ASDFHAS JEHLRUAIKYHE KURF ASJKDFHJ ASDFKJAHSDF ASDFASDF ASDF ASDFASDFASDF QWETR DGFsdqwerhdf adf qwer hdfashdf aE HFASDJFH ASKDFH QWLIULER HASDLIDLF HASDKJFH SDJF HAWEUJRH AS DKJFHL AWIUE4R YAS DJHFWIERUHF AUDF JHAWHWER ASJDFH ASDFHAS JEHLRUAIKYHE KURF ASJKDFHJ ASDFKJAHSDF ASDFASDF ASDF ASDFASDFASDF QWETR DGF"
android:textSize="20dp" />
</ScrollView>
</LinearLayout>
EDIT:: EDIT:
In order to get the line, here is a possible solution:
Android TextView and getting line of text
As I said at the commentary, firstly get a vector that contains every line, then look for the word. And finally move to the current row with the previous code.