如何实现下拉刷新,并拉起的扩展列表视图刷新 [英] How to implement Pull down to Refresh and pull up to refresh in Expandable List View

查看:193
本文介绍了如何实现下拉刷新,并拉起的扩展列表视图刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现下拉刷新,并拉起扩展列表视图刷新。
我使用的扩展列表视图。下面是用java code包含可扩展列表视图。

 公共类LoadMoreListView扩展ExpandableListView实现OnScrollListener {私有静态最后弦乐TAG =LoadMoreListView;/ **
 *监听,每次都会收到通知的列表滚动。
 * /
私人OnScrollListener mOnScrollListener;
私人LayoutInflater mInflater;//页脚视图
私人的RelativeLayout mFooterView;
//私人TextView的mLabLoadMore;
私人进度mProgressBarLoadMore;//监听器来处理负载更多的物品,当用户到达列表的末尾
私人OnLoadMoreListener mOnLoadMoreListener;
//要知道如果列表加载多个项目
私人布尔mIsLoadingMore = FALSE;
私人诠释mCurrentScrollState;公共LoadMoreListView(上下文的背景下){
    超级(上下文);
    初始化(上下文);
}公共LoadMoreListView(上下文的背景下,ATTRS的AttributeSet){
    超(背景下,ATTRS);
    初始化(上下文);
}公共LoadMoreListView(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
    超(背景下,ATTRS,defStyle);
    初始化(上下文);
}私人无效的init(上下文的背景下){    mInflater =(LayoutInflater)上下文
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);    //页脚
    mFooterView =(RelativeLayout的)mInflater.inflate(
            R.layout.load_more_footer,这一点,假);
    / *
     * mLabLoadMore =(TextView中)mFooterView
     * .findViewById(R.id.load_more_lab_view);
     * /
    mProgressBarLoadMore =(进度)mFooterView
            .findViewById(R.id.load_more_progressBar);    addFooterView(mFooterView);    super.setOnScrollListener(本);
}@覆盖
公共无效setAdapter(ListAdapter适配器){
    super.setAdapter(适配器);
}/ **
 *设置将收到通知,每次列表中的监听器
 *卷轴。
 *
 * @参数升
 *滚动侦听器。
 * /
@覆盖
公共无效setOnScrollListener(AbsListView.OnScrollListener L){
    mOnScrollListener = 1;
}/ **
 *注册一个回调被调用时,这个名单到达终点(最后
 *项目可见)
 *
 * @参数onLoadMoreListener
 *回调运行。
 * /公共无效setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener){
    mOnLoadMoreListener = onLoadMoreListener;
}公共无效onScroll(AbsListView观点,诠释firstVisibleItem,
        INT visibleItemCount,诠释totalItemCount){    如果(mOnScrollListener!= NULL){
        mOnScrollListener.onScroll(查看,firstVisibleItem,
                visibleItemCount,totalItemCount);
    }    如果(mOnLoadMoreListener!= NULL){        如果(visibleItemCount == totalItemCount){
            mProgressBarLoadMore.setVisibility(View.GONE);
            // mLabLoadMore.setVisibility(View.GONE);
            返回;
        }        布尔loadMore = firstVisibleItem + visibleItemCount> = totalItemCount;        如果(mIsLoadingMore&安培;!&安培; loadMore
                &功放;&安培; mCurrentScrollState!= SCROLL_STATE_IDLE){
            mProgressBarLoadMore.setVisibility(View.VISIBLE);
            // mLabLoadMore.setVisibility(View.VISIBLE);
            mIsLoadingMore = TRUE;
            onLoadMore();
        }    }}公共无效onScrollStateChanged(AbsListView观点,诠释scrollState){
    mCurrentScrollState = scrollState;    如果(mOnScrollListener!= NULL){
        mOnScrollListener.onScrollStateChanged(查看,scrollState);
    }}公共无效onLoadMore(){
    Log.d(TAGonLoadMore);
    如果(mOnLoadMoreListener!= NULL){
        mOnLoadMoreListener.onLoadMore();
    }
}/ **
 *通知装载更多的操作已完成
 * /
公共无效onLoadMoreComplete(){
    mIsLoadingMore = FALSE;
    mProgressBarLoadMore.setVisibility(View.GONE);
}/ **
 当列表到达被调用*回调接口定义
 *最后一个项目(在列表中的用户负载更多的物品)
 * /
公共接口OnLoadMoreListener {
    / **
     *当列表到达最后一个项目叫(最后一个项目是可见
     *给用户)
     * /
    公共无效onLoadMore();
}

}

下面是我将使用XML布局文件:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:layout_marginBottom =15dp
        机器人:layout_marginLeft =10dp
        机器人:layout_marginRight =10dp
        机器人:方向=垂直>        < ExpandableListView
            机器人:ID =@ + ID / listViewMeeting
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
             机器人:cacheColorHint =@色/白
            机器人:listSelector =@颜色/反式preNT
            机器人:groupIndicator =@颜色/反式preNT>        < / ExpandableListView>    < / LinearLayout中>< / LinearLayout中>


解决方案

该库支持ExpandableListView与PullToRefresh。

替换您的< ExpandableListView> < com.handmark.pulltorefresh.library。 PullToRefreshExpandableListView方式>

I want to implement Pull down to Refresh and pull up to refresh with Expandable List View. I am using Expandable List View. Below is java code that contain Expandable List View.

public class LoadMoreListView extends ExpandableListView implements OnScrollListener {

private static final String TAG = "LoadMoreListView";

/**
 * Listener that will receive notifications every time the list scrolls.
 */
private OnScrollListener mOnScrollListener;
private LayoutInflater mInflater;

// footer view
private RelativeLayout mFooterView;
// private TextView mLabLoadMore;
private ProgressBar mProgressBarLoadMore;

// Listener to process load more items when user reaches the end of the list
private OnLoadMoreListener mOnLoadMoreListener;
// To know if the list is loading more items
private boolean mIsLoadingMore = false;
private int mCurrentScrollState;

public LoadMoreListView(Context context) {
    super(context);
    init(context);
}

public LoadMoreListView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context);
}

public LoadMoreListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context);
}

private void init(Context context) {

    mInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // footer
    mFooterView = (RelativeLayout) mInflater.inflate(
            R.layout.load_more_footer, this, false);
    /*
     * mLabLoadMore = (TextView) mFooterView
     * .findViewById(R.id.load_more_lab_view);
     */
    mProgressBarLoadMore = (ProgressBar) mFooterView
            .findViewById(R.id.load_more_progressBar);

    addFooterView(mFooterView);

    super.setOnScrollListener(this);
}

@Override
public void setAdapter(ListAdapter adapter) {
    super.setAdapter(adapter);
}

/**
 * Set the listener that will receive notifications every time the list
 * scrolls.
 * 
 * @param l
 *            The scroll listener.
 */
@Override
public void setOnScrollListener(AbsListView.OnScrollListener l) {
    mOnScrollListener = l;
}

/**
 * Register a callback to be invoked when this list reaches the end (last
 * item be visible)
 * 
 * @param onLoadMoreListener
 *            The callback to run.
 */

public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
    mOnLoadMoreListener = onLoadMoreListener;
}

public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {

    if (mOnScrollListener != null) {
        mOnScrollListener.onScroll(view, firstVisibleItem,
                visibleItemCount, totalItemCount);
    }

    if (mOnLoadMoreListener != null) {

        if (visibleItemCount == totalItemCount) {
            mProgressBarLoadMore.setVisibility(View.GONE);
            // mLabLoadMore.setVisibility(View.GONE);
            return;
        }

        boolean loadMore = firstVisibleItem + visibleItemCount >= totalItemCount;

        if (!mIsLoadingMore && loadMore
                && mCurrentScrollState != SCROLL_STATE_IDLE) {
            mProgressBarLoadMore.setVisibility(View.VISIBLE);
            // mLabLoadMore.setVisibility(View.VISIBLE);
            mIsLoadingMore = true;
            onLoadMore();
        }

    }

}

public void onScrollStateChanged(AbsListView view, int scrollState) {
    mCurrentScrollState = scrollState;

    if (mOnScrollListener != null) {
        mOnScrollListener.onScrollStateChanged(view, scrollState);
    }

}

public void onLoadMore() {
    Log.d(TAG, "onLoadMore");
    if (mOnLoadMoreListener != null) {
        mOnLoadMoreListener.onLoadMore();
    }
}

/**
 * Notify the loading more operation has finished
 */
public void onLoadMoreComplete() {
    mIsLoadingMore = false;
    mProgressBarLoadMore.setVisibility(View.GONE);
}

/**
 * Interface definition for a callback to be invoked when list reaches the
 * last item (the user load more items in the list)
 */
public interface OnLoadMoreListener {
    /**
     * Called when the list reaches the last item (the last item is visible
     * to the user)
     */
    public void onLoadMore();
}

}

Below is Xml Layout File that i will use:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:orientation="vertical" >

        <ExpandableListView
            android:id="@+id/listViewMeeting"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
             android:cacheColorHint="@color/White"
            android:listSelector="@color/transprent"
            android:groupIndicator="@color/transprent" >

        </ExpandableListView>

    </LinearLayout>

</LinearLayout>

解决方案

This library supports ExpandableListView with PullToRefresh.

Replace your <ExpandableListView> with <com.handmark.pulltorefresh.library. PullToRefreshExpandableListView>.

这篇关于如何实现下拉刷新,并拉起的扩展列表视图刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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