如何实现快速滚动的ListFragment? [英] How to enable fast scrolling for a ListFragment?

查看:181
本文介绍了如何实现快速滚动的ListFragment?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个片段活动举办这使得一堆的产品列表片段:

I use a fragment activity to hold a list fragment which renders 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);
        ...
    }
}

我想<一个href=\"http://developer.android.com/reference/android/widget/AbsListView.html#setFastScrollEnabled%28boolean%29\"相对=nofollow>启用产品列表中快速滚动并发现它描述如何为做到这一点另一职务列表活动。但是,我怎么能激活快速滚动的片段?这将是没关系<一个href=\"http://developer.android.com/reference/android/widget/AbsListView.html#attr_android%3afastScrollEnabled\"相对=nofollow>在XML 或通过code定义此。

I want to enable fast scrolling for the list of products and found another post which describes how to do this for a list activity. But how can I activate fast scrolling for the fragment? It would be okay to define this in XML or via code.

推荐答案

SherlockListFragment 也有一个 getListView()方法的继承从ListFragment。

getListView().setFastScrollEnabled(true);

这是怎么可能看起来像你的里面 ListFragment

This is how it could 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);
}

这篇关于如何实现快速滚动的ListFragment?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆