问题
I have an activity with a TextView that has an onClick function.
After I click the TextView it should open a new activity and jump to a specific id(of e.g. another TextView) in the newly opened activity. Is there a possibility to do this?
回答1:
You can put your TextView and other elements inside a ScrollView and then you can use scrollTo(int x, int y) method of ScrollView to jump to the location of a specific element. You will need to find out the position of that specific element first.
回答2:
In your onCLick callback use an Intent to launch a new Activity. If necessary use the putExtra method on the Intent to add additional information, e.g. the TextView to "highlight".
Intent intent = new Intent(getBaseContext(), NewActivity.class);
intent.putExtra("TEXT_VIEW_ID", id);
startActivity(intent);
Then in the onCreate() method of NewActivity possibly use findViewById to get the TextView you need and then call requestFocus on it.
回答3:
This is what I needed:
scrollview.post(new Runnable() {
@Override
public void run() {
scrollview.smoothScrollTo(0, some_random_view_id.getTop());
}
});
来源:https://stackoverflow.com/questions/17633829/click-on-a-textview-opens-new-activity-and-jumps-to-a-specific-id