When listView pull down to refresh, why do click events trigger at the same time, and how do drop-down do not trigger click events

  android, question

import java.util.ArrayList;
import com.example.pull.view.MyListView;
import com.example.pull.view.MyListView.OnRefreshListener;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MainActivity extends Activity {

MyListView myListView;
 ArrayList<String> list=new ArrayList<String>();
 Myadapter adapter;
 
 private Handler handler=new Handler(){
 public void handleMessage(android.os.Message msg) {
 //update UI
 adapter.notifyDataSetChanged();
 
 myListView.completeRefresh();
 };
 };
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 initview();
 initData();
 bracket
private void initview() {
 setContentView(R.layout.activity_main);
 myListView=(MyListView) findViewById(R.id.myListView);
 
 bracket
 
 private void initData() {
 for (int i = 0;   i < 15;  I plus)
 List.add("listView original data-> "plus I);
 bracket
 
 adapter=new Myadapter();
 myListView.setAdapter(adapter);
 myListView.setOnRefreshListener(new OnRefreshListener() {
 
 @Override
 public void onPullRefresh() {
 //Require networking to request data from the server, and then update the UI
 requestDataFromServer(false);
 bracket
 
 @Override
 public void onLoadingMore() {
 requestDataFromServer(true);
 bracket
 });
 myListView.setOnItemClickListener(new OnItemClickListener() {
 
 @Override
 public void onItemClick(AdapterView<?  > parent, View view,
 int position, long id) {
 System.out.println ("click:" plus position ");
 bracket
 });
bracket
 
 private void requestDataFromServer(final boolean isLoadingMore){
 new Thread(){
 public void run(){
 SystemClock.sleep(3000);
 if(isLoadingMore){
 List.add ("pull-up refresh load data-> 1");
 List.add ("pull-up refresh load data-> 2");
 List.add ("pull-up refresh load data-> 3");
 }else{
 List.add(0, "Data for pull down to refresh");
 bracket
 
 //update UI on UI thread
 handler.sendEmptyMessage(0);
 bracket
 }.start();
 bracket
 
 
 
 
 class Myadapter extends BaseAdapter{
 @Override
 public int getCount() {
 
 return list.size();
 bracket
 
 @Override
 public Object getItem(int position) {
 
 return null;
 bracket
 
 @Override
 public long getItemId(int position) {
 
 return 0;
 bracket
 
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
 TextView textView=new TextView(MainActivity.this);
 textView.setPadding(20, 20, 20, 20);
 textView.setTextSize(18);
 textView.setText(list.get(position));
 return textView;
 bracket
 bracket

bracket

package com.example.pull.view;

import java.text.SimpleDateFormat;
import java.util.Date;
import com.example.pull.R;
import android.widget.AbsListView.OnScrollListener;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.RotateAnimation;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MyListView extends ListView implements OnScrollListener{

private View headerView,footerView;
 private ImageView iv;
 private ProgressBar pb;
 private TextView tv1,tv2;
 
 
 private int headerHeight,footerHeight;  //height of //headerView
 private int downY;  //get the current height of y
 private final int PULL_REFRESH=0;  //Status of pull down to refresh
 private final int RELEASE_REFRESH=1;  //Release the refresh status
 private final int REFRESHING=2;  //Refreshing status
 private int currentState=PULL_REFRESH;  //Default pull down to refresh Status
 private RotateAnimation upAnimation,downAnimation;
 
 private boolean isLoadingMore=false;  //Are you currently loading more
 
 
 public MyListView(Context context) {
 super(context);
 init();
 
 bracket
 
 public MyListView(Context context, AttributeSet attrs) {
 super(context, attrs);
 init();
 bracket
 public void init(){
 setOnScrollListener(this);
 initHeaderView();
 initRotateAnimation();
 initFooterView();
 bracket
//初始化headerView
private void initHeaderView() {
    headerView=View.inflate(getContext(), R.layout.layout_header, null);
    iv=(ImageView) headerView.findViewById(R.id.imageView);
    pb= (ProgressBar) headerView.findViewById(R.id.progressBar);
    tv1= (TextView) headerView.findViewById(R.id.textView1);
    tv2= (TextView) headerView.findViewById(R.id.textView2);
    
    
    headerView.measure(0, 0);//通知系统主动测量
    headerHeight=headerView.getMeasuredHeight();
    headerView.setPadding(0, -headerHeight, 0, 0);
    addHeaderView(headerView);
    
}

private void initRotateAnimation() {
    upAnimation=new RotateAnimation(0, -180,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    upAnimation.setDuration(300);
    upAnimation.setFillAfter(true);
    
    downAnimation=new RotateAnimation(-180, -360,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f);
    downAnimation.setDuration(300);
    downAnimation.setFillAfter(true);
}


@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        downY=(int) ev.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        
        if(currentState==REFRESHING){
            break;
        }
        
        
        int deltaY=(int) (ev.getY()-downY);
        int paddingTop=-headerHeight加deltaY;
        if(paddingTop>-headerHeight && getFirstVisiblePosition()==0){
        headerView.setPadding(0, paddingTop, 0, 0);
        if(paddingTop>=0 && currentState==PULL_REFRESH){
            //下拉刷新状态进入松开刷新状态
            currentState=RELEASE_REFRESH;
            refreshHeaderView();
        }else if (paddingTop<0 && currentState==RELEASE_REFRESH) {
            //松开刷新状态进入下拉刷新状态
            currentState=PULL_REFRESH;
            refreshHeaderView();
        }
        
        return true;
        }
        //return true;//拦截TouchMove,不让listView处理,会造成listView无法滑动
        
        break;
    case MotionEvent.ACTION_UP:
        if(currentState==PULL_REFRESH){
            headerView.setPadding(0, -headerHeight, 0, 0);
        }else if (currentState==RELEASE_REFRESH) {
            headerView.setPadding(0, 0, 0, 0);
            currentState=REFRESHING;
            refreshHeaderView();
            
            if(listener!=null){
                listener.onPullRefresh();
            }
        }
        break;

    default:
        break;
    }
    return super.onTouchEvent(ev);
}

 // 根据currentState来更新headerView

private void refreshHeaderView(){
    switch (currentState) {
    case PULL_REFRESH:
        tv1.setText("下拉刷新");
        iv.startAnimation(downAnimation);
        
        
        
        break;
    case RELEASE_REFRESH:
        tv1.setText("松开刷新");
        iv.startAnimation(upAnimation);
        break;
    case REFRESHING:
        tv1.setText("正在刷新...");
        iv.clearAnimation();//向上的旋转动画可能没有执行完
        iv.setVisibility(View.INVISIBLE);
        pb.setVisibility(View.VISIBLE);
        break;

    default:
        break;
    }
}

 // 完成刷新操作,重置状态,在获取完数据并更新完adapter之后,去在UI线程中调用
public void completeRefresh(){
    if(isLoadingMore){
        //重置footerView状态
        footerView.setPadding(0, -footerHeight, 0, 0);
        isLoadingMore=false;
    }else{
        //重置headerView状态
        headerView.setPadding(0, -headerHeight, 0, 0);
        currentState=PULL_REFRESH;
        
        iv.setVisibility(View.INVISIBLE);
        pb.setVisibility(View.VISIBLE);
        tv1.setText("下拉刷新");
        tv2.setText("最后刷新:"加getCurrentTime());
        
        pb.setVisibility(View.INVISIBLE);
        iv.setVisibility(View.VISIBLE);
    }
    
}
private String getCurrentTime(){
    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return format.format(new Date());
}

private OnRefreshListener listener;
public void setOnRefreshListener(OnRefreshListener listener){
    this.listener=listener;
}
public interface OnRefreshListener{
    void onPullRefresh();
    void onLoadingMore();
}

//尾部上拉加载
private void initFooterView() {
    footerView=View.inflate(getContext(), R.layout.layout_footer, null);
    footerView.measure(0, 0);//通知系统主动测量
    footerHeight=footerView.getMeasuredHeight();
    footerView.setPadding(0, -footerHeight, 0, 0);
    
    addFooterView(footerView);
    
}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    if(scrollState==OnScrollListener.SCROLL_STATE_IDLE
        && getLastVisiblePosition()==(getCount()-1) && !isLoadingMore){
        isLoadingMore=true;
        footerView.setPadding(0, 0, 0, 0);//显示出加载更多
        setSelection(getCount());//让listView最后一条显示出来
        
        if(listener!=null){
            listener.onLoadingMore();
        }
        
    }
}

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

bracket

Action _ move: return true;