【问题标题】:Need PullToRefershListView functionality with expandable list view需要具有可扩展列表视图的 PullToRefershListView 功能
【发布时间】:2015-03-06 05:34:58
【问题描述】:

实际上我必须应用两个功能第一个是拉刷新视图,第二个是列表视图中的动画可扩展子项。

当我单击列表项的按钮时,布局从上到下,当我再次单击此按钮时,此布局从下到上。我可以在 ExpanableCells 项目中看到这个功能。

而且我还需要在用户滚动列表视图时刷新我的列表。

对于这两个功能,我有两个项目 PullToRefreshView 库和 ExpandableCells 项目,但开发人员都以不同的方式应用 ListView,我无法同时使用它们。我只能使用其中的一个。

任何人都申请这两个请帮助我。或者我必须从基础实现它们。

【问题讨论】:

    标签: android expandablelistview pull-to-refresh


    【解决方案1】:

    你可以使用android提供的SwipeRefreshlayout,你需要支持库:android.support.v4.widget.SwipeRefreshLayout

    你也可以这样写你的xml布局:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.expandablelistviewwithpultoreferesh.MainActivity" >
    
    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <ExpandableListView
            android:id="@+id/lvExp"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v4.widget.SwipeRefreshLayout>
    
    </RelativeLayout>
    

    在 MainActivity 中,

    ExpandableListAdapter listAdapter;
    ExpandableListView expListView;
    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;
    private SwipeRefreshLayout swipeLayout;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        // get the listview
        expListView = (ExpandableListView) findViewById(R.id.lvExp);
    

    让您的活动实现 OnRefreshListener 并添加未实现的方法,即

    @Override
    public void onRefresh() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                swipeLayout.setRefreshing(false);
            }
        }, 5000);
    }
    

    实现的来源(教程): 可扩展的列表视图:- http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

    滑动刷新布局:- http://antonioleiva.com/swiperefreshlayout/

    注意:如果你想要一个动画 Expandable listView ,请确保你有一个更新的 Android SDK,你可以试试这个库 https://github.com/idunnololz/AnimatedExpandableListView 它只是扩展了 ExpandableListview

    【讨论】:

    • @Sachine,我必须像在 iPhone 中那样做类似的事情,我别无选择,但我找到了一种通过插值器来做到这一点的方法。我会尽快更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 2012-03-28
    相关资源
    最近更新 更多