当前位置:操作系统 > 安卓/Android >>

android ExpandableListView的下拉刷新实现

 

该控件的修改时根据PullToRefreshList的机制修改

 

下面是对ExpandableListView的扩展

 

 

package com.up91.gwy.view.componet; 

 

import java.lang.reflect.InvocationTargetException; 

import java.lang.reflect.Method; 

 

import com.up91.gwy.R; 

 

import android.content.Context; 

import android.util.AttributeSet; 

import android.view.LayoutInflater; 

import android.view.MotionEvent; 

import android.view.View; 

import android.view.ViewGroup; 

import android.view.animation.LinearInterpolator; 

import android.view.animation.RotateAnimation; 

import android.widget.AbsListView; 

import android.widget.ExpandableListView; 

import android.widget.AbsListView.OnScrollListener; 

import android.widget.ImageView; 

import android.widget.ListAdapter; 

import android.widget.ProgressBar; 

import android.widget.RelativeLayout; 

import android.widget.TextView; 

 

public class PullToRefreshExpandableListView 

        extends ExpandableListView 

        implements 

            OnScrollListener { 

     

    private static final String TAG = "PullToRefreshExpandableListView"; 

     

    private static final int TAP_TO_REFRESH = 1; 

    private static final int PULL_TO_REFRESH = 2; 

    private static final int RELEASE_TO_REFRESH = 3; 

    private static final int REFRESHING = 4; 

     

    private OnRefreshListener mOnRefreshListener; 

     

    private OnScrollListener mOnScrollListener; 

     

    private LayoutInflater  mInflater; 

     

    private RelativeLayout  mRefreshView; 

     

    private TextView mRefreshViewText; 

     

    private ImageView mRefreshViewImage; 

     

    private ProgressBar mRefreshViewProgress; 

     

    private TextView   mRefreshViewLastUpdated; 

     

    private int mCurrentScrollState; 

     

    private int mRefreshState; 

     

    private RotateAnimation mFlipAnimation; 

     

    private RotateAnimation mReverseFlipAnimation; 

     

    private int mRefreshViewHeight; 

     

    private int mRefreshOriginalTopPadding; 

     

    private int mLastMotionY; 

     

    private boolean isInInitState; 

     

    public PullToRefreshExpandableListView(Context context) { 

        super(context); 

        init(context); 

    } 

 

    public PullToRefreshExpandableListView(Context context, AttributeSet attrs) { 

        super(context,attrs); 

        init(context); 

    } 

     

    public PullToRefreshExpandableListView(Context context,AttributeSet attrs, int defStyle) { 

        super(context,attrs,defStyle); 

        init(context); 

    } 

     

    private void init(Context context){ 

        mFlipAnimation = new RotateAnimation(0,-180, 

                RotateAnimation.RELATIVE_TO_SELF,0.5f, 

                RotateAnimation.RELATIVE_TO_SELF,0.5f); 

        mFlipAnimation.setInterpolator(new LinearInterpolator()); 

        mFlipAnimation.setDuration(250); 

        mFlipAnimation.setFillAfter(true); 

        mReverseFlipAnimation = new RotateAnimation(-180,0, 

                RotateAnimation.RELATIVE_TO_SELF,0.5f, 

                RotateAnimation.RELATIVE_TO_SELF,0.5f); 

        mReverseFlipAnimation.setInterpolator(new LinearInterpolator()); 

        mReverseFlipAnimation.setDuration(250); 

        mReverseFlipAnimation.setFillAfter(true); 

         

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

         

        mRefreshView = (RelativeLayout) mInflater.inflate(R.layout.pull_to_refresh_header, this,false); 

     

        mRefreshViewText = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text); 

         

        mRefreshViewImage = (ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image); 

         

        mRefreshViewProgress = (ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress); 

     

        mRefreshViewLastUpdated = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_updated_at); 

     

        mRefreshViewImage.setMinimumHeight(

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,