SwipeRefreshLayout in Android v4 package official pull-down refresh component

Source: Internet
Author: User

SwipeRefreshLayout in Android v4 package official pull-down refresh component

SwipeRefreshLayout is in the v4 package, and corresponding examples are also provided in the corresponding v4Demo. If not, download the latest support-v4

SwipeRefreshLayout can have only one direct sub-View, which may be a ListView, a Layout, or other components to be refreshed.

SetOnRefreshListener is used to listen for refreshing actions. The SwipeRefreshLayout drop-down will have a refreshing effect and trigger this listener.

If you need a refresh animation, setRefreshing (true), stop: setRefreshing (false)

If you want to disable refresh animation and gesture response, ssetEnable (false), restore setEnable (true)


Here is an example of v4:

public class SwipeRefreshLayoutActivity extends Activity implements OnRefreshListener {    public static final String[] TITLES =    {            "Henry IV (1)",            "Henry V",            "Henry VIII",            "Richard II",            "Richard III",            "Merchant of Venice",            "Othello",            "King Lear",            "Henry IV (1)",            "Henry V",            "Henry VIII",            "Richard II",            "Richard III",            "Merchant of Venice",            "Othello",            "King Lear",            "Henry IV (1)",            "Henry V",            "Henry VIII",            "Richard II",            "Richard III",            "Merchant of Venice",            "Othello",            "King Lear",            "Henry IV (1)",            "Henry V",            "Henry VIII",            "Richard II",            "Richard III",            "Merchant of Venice",            "Othello",            "King Lear"    };    // Try a SUPER quick refresh to make sure we don't get extra refreshes    // while the user's finger is still down.    private static final boolean SUPER_QUICK_REFRESH = false;    private View mContent;    private SwipeRefreshLayout mSwipeRefreshWidget;    private ListView mList;    private Handler mHandler = new Handler();    private final Runnable mRefreshDone = new Runnable() {        @Override        public void run() {            mSwipeRefreshWidget.setRefreshing(false);        }    };    @Override    public void onCreate(Bundle bundle) {        super.onCreate(bundle);        setContentView(R.layout.swipe_refresh_widget_sample);        mSwipeRefreshWidget = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget);        mSwipeRefreshWidget.setColorScheme(R.color.color1, R.color.color2, R.color.color3,                R.color.color4);        mList = (ListView) findViewById(R.id.content);        ArrayAdapter
 
   arrayAdapter = new ArrayAdapter
  
   (this,                android.R.layout.simple_list_item_1, android.R.id.text1, TITLES);        mList.setAdapter(arrayAdapter);        mSwipeRefreshWidget.setOnRefreshListener(this);        mSwipeRefreshWidget.setProgressViewEndTarget(false, 8);    }    @Override    public void onRefresh() {        refresh();    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        MenuInflater inflater = getMenuInflater();        inflater.inflate(R.menu.swipe_refresh_menu, menu);        return true;    }    /**     * Click handler for the menu item to force a refresh.     */    @Override    public boolean onOptionsItemSelected(MenuItem item) {        final int id = item.getItemId();        switch(id) {            case R.id.force_refresh:                mSwipeRefreshWidget.setRefreshing(true);                refresh();                return true;        }        return false;    }    private void refresh() {        mHandler.removeCallbacks(mRefreshDone);        mHandler.postDelayed(mRefreshDone, 1000);    }}
  
 

Swipe_refresh_widget_sample.xml

    
     
 



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.