2017-10-17 2 views
0

私はアプリケーションでSmoothRefreshLayoutライブラリを実装しました。これは現時点では単純なListViewを持っています。 問題は、ListViewをスクロールダウンするときに発生し、スクロールせずに上に移動しようとすると、リフレッシュリスナーが呼び出されます。その動きは止まっています。ListViewはSmoothRefreshLayoutを使用してバグをスクロールします

これはactivity_main.xml

<?xml version="1.0" encoding="utf-8"?> 

<me.dkzwm.widget.srl.SmoothRefreshLayout 

    android:id="@+id/smoothRefreshLayout" 
    android:layout_width="match_parent" 

    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_height="match_parent"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <ProgressBar 
     android:id="@+id/progressBar" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_centerInParent="true" 
     android:indeterminateDrawable="@drawable/circular_spinner" > 
    </ProgressBar> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/lv" 

     /> 
</RelativeLayout> 
</me.dkzwm.widget.srl.SmoothRefreshLayout> 

であり、これはのonCreateでRefreshListenerの一部です:

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getSupportActionBar().setTitle(""); 
     setContentView(R.layout.activity_main); 

     refreshLayout = (SmoothRefreshLayout)findViewById(R.id.smoothRefreshLayout); 
     refreshLayout.setHeaderView(new MyCustomHeader(this)); 

     refreshLayout.setEnabled(true); 
     refreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() { 
      @Override 
      public void onRefreshBegin(boolean isRefresh) { 

       if (isNetworkAvailable(MainActivity2.this)) { 
        isRef = true; 
        new upd().execute(); 
       } else { 
        Toast.makeText(MainActivity2.this, getResources().getString(R.string.err_conn), Toast.LENGTH_SHORT).show(); 
       } 

      } 

     }); 

答えて

0

私はそれが自己の返信には意味がありません知っているが、それが役立つかもしれません他の誰か。 とにかく、解決策は簡単です。私はちょうどonScrollListenerを実装して、リフレッシャーを無効にするのではなく、最初のアイテムが上部にあるかどうかを確認しました。

listView.setOnScrollListener(new AbsListView.OnScrollListener() { 
      @Override 
      public void onScrollStateChanged(AbsListView view, int scrollState) { 

      } 

      @Override 
      public void onScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 
       int rowpos = (listView == null || listView.getChildCount() == 0) ? 
         0 : listView.getChildAt(0).getTop(); 
       refreshLayout.setEnabled((rowpos >= 0)); 
      } 
     }); 

クレジット:Can't scroll in a ListView in a swipeRefreshLayout

関連する問題