How to enable fast scrolling for ListFragment?

I use the fragment operation to store a list fragment that displays a bunch of products:

public class ProductsListActivity extends SherlockFragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { setTheme(R.style.Sherlock___Theme); super.onCreate(savedInstanceState); setContentView(R.layout.fragment_products_list); // setFastScrollEnabled(true) ? } } 

...

 <!-- fragment_products_list.xml --> <?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:name="com.example.fragment.ProductsListFragment" android:id="@+id/list_fragment" android:layout_width="match_parent" android:layout_height="match_parent" /> 

...

 public class ProductsListFragment extends SherlockListFragment { @Override public void onViewCreated(View view, Bundle savedInstanceState) { // setFastScrollEnabled(true) ? super.onViewCreated(view, savedInstanceState); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ... } } 

I want to enable fast scrolling for a list of products and found another message that describes how to do this for list activity. But how can I activate fast scrolling of a fragment? It would be nice to define this in XML or through code.

+2
android android-listview android-fragments android-listfragment
Sep 06 '13 at 17:57
source share
1 answer

SherlockListFragment also has a getListView() method inherited from ListFragment.

 getListView().setFastScrollEnabled(true); 

Here's what it might look like inside your ListFragment :

 @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ArrayList<String> strings = new ArrayList<String>(); for(int i = 0; i < 300; i++) strings.add("Item " + i); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, strings); setListAdapter(adapter); getListView().setFastScrollEnabled(true); } 
+2
Sep 06 '13 at 18:39
source share



All Articles