ScrollTo Method Not Used

I made an Android program to read books. And I want to be able to open the tag, and when you open the tag, the program will open the book and move to the position indicated in the tag.

But in my application, the ScrollTo function does not respond.

Here is my code.

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.reader); scrollView = (ScrollView)findViewById(R.id.Scroll); text = (TextView)findViewById(R.id.text); tagsButton = (ImageButton)findViewById(R.id.Tags); openButton = (ImageButton)findViewById(R.id.Open); text.setTextColor(Color.RED); text.scrollTo(0, index); }//Here the scrollTo do not work... 

The process in onCreate is not important, so I delete them.

What puzzles me is that in the method below, scrolling the method might work ...

 protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(data!=null){ Bundle bundle = data.getExtras(); if(bundle!=null){ int index = bundle.getInt("Index"); String file_name = bundle.getString("File_Name"); ReadFile(file_name); scrollView.scrollTo(0, index); text.postInvalidate(); } } 

I donโ€™t think there is such a difference between the two methods ... But why ...

Can anybody help me?

thanks a lot.

+4
source share
1 answer

in your onCreate attempt

  text.post(new Runnable() { @Override public void run() { text.scrollTo(...); } }); 
+7
source

All Articles