I have tried to use both ScrollView and ListView.
I figured out that if I use ListView and I click one of items let current fragment be replaced by next fragment and press back button to prev fragment. The scroll position of ListView will keep at same position. But if I use ScrollView, it will not.
I don't understand why they are different? And how can I make ScrollView keep its position after press back button?
Actually, I have searched some answer at StackOverflow. But I want to know the reasons and find an easier way to make ScrollView and ListView have same behavior.
Please help me! Thank you!
You can try $("div#element"). load(function() {}) and place the element outside the document ready handler. Also, if a user scroll down the page, then leave the page, and go back to the page again, it should be a new start for him so it should start at the top. But now it also remembers the previous position.
ScrollView is used to put different or same child views or layouts and the all can be scrolled. ListView is used to put same child view or layout as multiple items. All these items are also scrollable. Simply ScrollView is for both homogeneous and heterogeneous collection.
In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.
ListView itself is scrollable.
Fragments automatically save and restore the states of their Views, as long they have IDs assigned.
So if you assign an ID to your ScrollView, its scroll state can be restored:
<ScrollView android:id="@+id/scrollview" ...>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With