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!!!
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());
}
});
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
Related
I've a ScrollView, inside that there are few views one of them is a TextView. I'm pragmatically setting current time to the TextView. Therefore TextView updates every second. Now when I over scroll ScrollView, the ScrollView moves to top. I guess its losing touch when TextView updates.
So how can I prevent ScrollView to move to top?
That's your friend:
android:descendantFocusability="blocksDescendants"
Set this attribute to the Elements INSIDE of the ScrollView.
But since this removes the focusability of the elements you won't be able to edit any inputs like EditText etc.
In this case you could "prevent" the ScrollView from scrolling to the current focus (it does not scroll "to the top") by ensuring the focus to be at the position I like.
To give an example:
I've got a ScrollView with a TableView inside and a CheckBox in each row of the table. When I check one of them, the color of the current row is to be changed. But: the moment I set the color, the ScrollView scrolls to the focus.
So I set the focus to the ckeckbox I just clicked before I change the color:
// enable focusability if necessary:
// cbOK.setFocusable(true);
// cbOK.setFocusableInTouchMode(true);
cbOK.requestFocus();
row.setBackgroundColor(....);
I have a listview and button in a scrollview. When i scroll both list and button loses focus. When i tap on button it did not work but next time i tap it works i think button loses focus and focus is towards scrollview how to handle this please help
Never put ListView inside a ScrollView. ListView handles scrolling, and wrapping it in a ScrollView can cause problems with focus, touch-events etc. If you want other Views added to the top or bottom of you list, simply use ListView.addHeaderView() or ListView.addFooterView()
Scroll view can have only one child, put your button and listview in common layout and try out.
I have a LinearLayout containing two ImageViews. The LinearLayout is inside the ScrollView.
When I scroll the screen I would like to know the exact position of the two ImageViews relative to scroll. The getScrollY() doesn't work correctly because the ImageViews continues scrolling after action_up and the value in getScrollY isn't updated in this case. I have this information to disable or enable other elements on screen.
If your 2 views are the same/similar then add them to a ListView, then you can set an OnScrollListener which will tell you when the view is scrolled and the index of the visible item.
I have a edittext and textview next to each other. I'd like, when I scroll with the edittext(either with finger or by adding new content to edittext) that the textview scroll the same distance. I've tried querying the getScrollY
I am not sure if I understand your question perfectly, but if I do, then I would suggest putting these two elements side by side in a Horizontal linear layout within a Scroll View. This way if / when either of the elements are moved, they will stay with each other.
I have a Listview in which there are 3-4 textviews. I am using the BaseAdapter way where I am inflating xml. All the textviews are single line. I want to make the textview horizontally scrollable. I have tried to put the textview inside HorizontalScrollview. Well, that did scrolled the textview but then I was not able to get the click event of listview.
Is there any other way I can make the textview scrollable horizontally?
I was able to solve this issue by adding this line to first RelativeLayout in the xml file android:descendantFocusability="blocksDescendants". In this way no child will have focus and so the horizontal scrollbar also works and listview item clicks also works. It worked for me. Anyways, thanks everyone.
AFAIK there is no easy way to do this.
The problem is that scroll view consume all touch events. To solve this one should make sure that horizontal scroll view consume only "horizontal" move events.
First you should implement you own scroll view. Then override onTouchEvent() of that view so it only consume "more horizontal than vertical" gestures and left "vertical" gestures for list view.
You can try to use the ellipsize property of the TextView class. If you set it to marquee the text should automatically scroll when it is focused.
Why don't anybody use TextView.setMovementMethod(ScrollingMovementMethod.getInstance()) with android:scrollHorisontally="true"?