Click on a TextView opens new activity and jumps to a specific id

≯℡__Kan透↙ 提交于 2019-12-11 15:47:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!