讓 Android 支援下拉重新整理(Pull Refresh)

來源:互聯網
上載者:User

 曾幾何時,自 Android 發布之後一直以來就被管以 Geek 的玩具,而不太注重介面設計和使用者互動設計,這讓 Android 開發人員也順其自然的接受了這個不好的頭銜,但我一度認為這隻是不思進取的行為,誰說 Android 就不能像 iPhone 的介面那樣設計,我認為只有用心,沒神馬不能實現的。說回正題,第一次看到 Android 有這項功能的莫過於改版後的 Twitter,我認為它絕對是一個標榜性的 App(同時也包括已開源許久的Foursquare)。於是全世界的開發人員就開始尋思這個效果
Twitter 是如何?的,於是就有了...

這是由
johannilsson 以及眾位其好友的研究成果,並已 Apache 2.0 協議開源託管在 Github:https://github.com/johannilsson/android-pulltorefresh

大概看了一下源碼,發現和我初步的想法類似,除了需要整合系統的 ListView 之外,只能在 HeaderView 上面做文章,外加配合 onTouchEvent, onScroll 事件可以捕捉使用者下拉和上滑的事件監聽。

用法:

Layout

<!--  The PullToRefreshListView replaces a standard ListView widget.--><com.markupartist.android.widget.PullToRefreshListView    android:id="@+id/android:list"    android:layout_height="fill_parent"    android:layout_width="fill_parent"    />

Activity

// Set a listener to be invoked when the list should be refreshed.((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {    @Override    public void onRefresh() {        // Do work to refresh the list here.        new GetDataTask().execute();    }}); private class GetDataTask extends AsyncTask<Void, Void, String[]> {    ...    @Override    protected void onPostExecute(String[] result) {        mListItems.addFirst("Added after refresh...");        // Call onRefreshComplete when the list has been refreshed.        ((PullToRefreshListView) getListView()).onRefreshComplete();        super.onPostExecute(result);    }}

 

?倉庫裡除了實作類別外,還有一個執行個體,看看人家夠意思吧。
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.