1

I have an EditText with number input, a button and a ScrollView one below the other.

Inside the ScrollView I have a Linear Layout with vertical orientation and inside the Layout I have about 50 TextViews each with id 1,2,3,4....

What I want is that when the user enters a number in EditText and clicks the button,it should read which number is entered (say 28),then the ScrollView should scroll Textview with id 28 without disturbing the others.

I have no problem if I have to type the same code for each and every TextView even 500 times but it should be a working code like I mentioned above.

I have been trying to achieve this for a while without any success.Please Help!!!

Furqan Hussain
  • 135
  • 1
  • 4
  • 14
  • 2
    try to use recycleView, refer to this link https://developer.android.com/guide/topics/ui/layout/recyclerview.html – Truong Giang Dam Jan 09 '18 at 09:14
  • With that many items inside the scrollview and LinearLayout, RecyclerView is more better choice as suggested. It is created to serve this exact purpose. Your approach is very bad – Vijai Jan 09 '18 at 09:23

2 Answers2

1

Find the view at that position in LinearLayout and scroll to that view

scrollView.post(new Runnable() { 
            public void run() { 
                 scrollView.scrollTo(0, parentLinearLayoute.getChidAt(position).getBottom());
            } 
    });
MJM
  • 5,119
  • 5
  • 27
  • 53
0

You will have to replace Scrollview and Linearlayout with RecylerView. And you can use smoothScrollToPosition to scroll to a particular position. I think this should be the best approach