Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing a "faster" backToTop - ListView
    primarykey
    data
    text
    <p>I have a ListView inside a Fragment, which is added as a tab inside a ViewPager. I want the users to be able to scroll "backToTop" by simply tapping on the Tab they are already on (<strong>onTabReselected()</strong>). I already have a working code to do this; However, the code I use takes too long to scroll back to position 0, which is pretty neat on small lists, but on a 250 song collection it can certainly annoy a user. </p> <p>Here's my code: </p> <pre><code>@Override public void onTabReselected(Tab tab, FragmentTransaction ft) { switch (tab.getPosition()) { case 0: if (tab.getPosition() == mCurPagerItem) { final ListView list = (ListView) findViewById(android.R.id.list); list.smoothScrollToPosition(0); } break; case 1: if (tab.getPosition() == mCurPagerItem) { final GridView list = (GridView) findViewById(R.id.artist_grid); list.smoothScrollToPosition(0); } break; case 2: if (tab.getPosition() == mCurPagerItem) { final ExpandableListView list = (ExpandableListView) findViewById(R.id.exp_list); list.smoothScrollToPosition(0); } break; default: break; } } </code></pre> <p>Where I switch between positons as my different fragments have different "list" types. As I said, this code works certainly well, but is there a faster way to scroll back to top? Something that is more instant that is. </p> <p>And just to clarify, when I say it "takes too long", that is because <strong>smoothScrollToPosition</strong> is in itself a slow way to scroll on the list, supposedly to make it nicer looking. </p> <p><strong>Note</strong> I did try: </p> <pre><code>list.scrollTo(0, 0); </code></pre> <p>but that actually doesn't seem to do anything to the listView's current position. I imagine that is more a View call, that a ListView method itself. </p> <p>Any ideas? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload