user3538235
user3538235

Reputation: 2009

Scroll to particular Text view inside the Scroll view

There is a program generated scroll view like this:

The scroll view XML is just simple empty LinearLayout

<ScrollView>
<LinearLayout>
</LinearLayout>
</ScrollView>

Then , in the run time , I have an ArrayList<TextView>, and add the items to the ScrollView like this

for (TextView t : test_views) {
     scroll_view.addView(t);
}

And now , I have one of the listView and I would like to scroll to that TextView programmatic , the case is quite special so that can not change the scrollview to listview, how to achieve that?

Thanks a lot for helping.

Upvotes: 2

Views: 179

Answers (2)

Febi M Felix
Febi M Felix

Reputation: 2839

Try using scrollTo() function. More details available in this link http://developer.android.com/reference/android/widget/ScrollView.html#scrollTo(int, int)

Upvotes: 2

Vatsal Shah
Vatsal Shah

Reputation: 547

Please check the below code.

sv.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                tv.getParent().requestDisallowInterceptTouchEvent(false);

                return false;
            }
        });

tv.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                tv.getParent().requestDisallowInterceptTouchEvent(true);

                return false;
            }
        });

Hope it will help you.

Let me know if you need any further help.

Upvotes: 1

Related Questions