android下拉重新整理控制項之第三方開原始檔控制的使用實現

來源:互聯網
上載者:User

標籤:android   下拉重新整理   控制項   

本次使用的第三方下拉重新整理控制項是:Android-Pull-Refresh,:https://github.com/chrisbanes/Android-PullToRefresh

該控制項適用於:

  • ViewPager
  • HorizontalScrollView
  • ScrollView
  • WebView
  • GridView
  • ListView
  • ExpandableListView
  • ListFragment

從github上下載解壓後,將library,PullToRefreshListFragment,PullToRefreshViewPager匯入項目後,右鍵自己建立的項目,選擇Properties,進入如的頁面後點擊Add添加即可:
添加好後即可開始編寫Demo,具體代碼如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <!-- The PullToRefreshListView replaces a standard ListView widget. -->    <com.handmark.pulltorefresh.library.PullToRefreshListView        xmlns:ptr="http://schemas.android.com/apk/res-auto"        android:id="@+id/pull_refresh_list"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:cacheColorHint="#00000000"        android:divider="#19000000"        android:dividerHeight="4dp"        android:fadingEdge="none"        android:fastScrollEnabled="false"        android:footerDividersEnabled="false"        android:headerDividersEnabled="false"        android:smoothScrollbar="true"        ptr:ptrDrawable="@drawable/ic_launcher"        ptr:ptrMode="both" /></LinearLayout>

import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.os.AsyncTask;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.Toast;import com.handmark.pulltorefresh.library.PullToRefreshBase;import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener;import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;import com.handmark.pulltorefresh.library.PullToRefreshListView;/** * MainActivity---利用第三方下拉重新整理控制項實現 * @author seabear * */public class MainActivity extends Activity {private PullToRefreshListView mPullToRefreshListView;private List<String> mArrayList = new ArrayList<String>();private ArrayAdapter<String> mArrayAdapter;private int mNums = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mPullToRefreshListView = (PullToRefreshListView)this.findViewById(R.id.pull_refresh_list);mArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mArrayList);mPullToRefreshListView.setAdapter(mArrayAdapter);mPullToRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {@Overridepublic void onRefresh(PullToRefreshBase<ListView> refreshView) {// TODO Auto-generated method stubnew GetDataTask().execute();}});}private class GetDataTask extends AsyncTask<Void, Void, String>{@Overrideprotected String doInBackground(Void... params) {// Simulates a background job.mNums++;try {Thread.sleep(2000);} catch (InterruptedException e) {}return "第" + String.valueOf(mNums) + "行";}@Overrideprotected void onPostExecute(String result) {mArrayList.add(result);mArrayAdapter.notifyDataSetChanged();// Call onRefreshComplete when the list has been refreshed.mPullToRefreshListView.onRefreshComplete();super.onPostExecute(result);}}}



著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

android下拉重新整理控制項之第三方開原始檔控制的使用實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.