Code Monkey home page Code Monkey logo

android-pull-to-refresh's Introduction

怎麼把這專案匯入Android Studio

  • 要選Import Project...

Android Studio 匯入專案

*** # [SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html)

SwipeRefreshLayoutFragment.java

fragment_swipe_refresh_layout.xml

注意如果沒有下面這段程式,重整中切換fragment會卡住

@Override
public void onPause() {
  super.onPause();
  if (swipeRefreshLayout!=null) {
    swipeRefreshLayout.setRefreshing(false);
    swipeRefreshLayout.clearAnimation();
  }
}

PullToRefreshFragment.java

fragment_pull_to_refresh.xml

  • 這個library有好多header可以用,這邊使用的是StoreHouseHeader

  • 注意若是使用PtrHandler要實作checkCanDoRefresh否則想ListView這種會無法往上滑(會直接觸發refresh)

ptrFrameLayout.setPtrHandler(new PtrHandler() {
  @Override
  public boolean checkCanDoRefresh(PtrFrameLayout ptrFrameLayout, View view, View view2) {
    boolean canDoRefresh;
    //TODO: check if canDoRefresh or not
    return canDoRefresh;
  }
  @Override
    public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) {
      //TODO: refresh code...
   }
});
  • 而使用PtrDefaultHandler會自動checkCanDoRefresh,在ListViewGridView上測試狀況良好
ptrFrameLayout.setPtrHandler(new PtrDefaultHandler() {
  @Override
  public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) {
    //TODO: refresh code...
  }
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.