google推出的SwipeRefreshLayout下拉重新整理用法

來源:互聯網
上載者:User

SwipeRefreshLayout是Google在support v4 19.1版本的library更新的一個下拉重新整理組件,實現重新整理效果更方便。

使用如下:

1.先下載android-support-v4.jar最新版本,之前的版本是沒有SwipeRefreshLayout下拉重新整理控制項的,如果已經更新,此步驟可省略。

2.在xml檔案中引用android.support.v4.widget.SwipeRefreshLayout控制項,在裡面可以放置任何一個控制項,例如ListView,gridview等。

    <android.support.v4.widget.SwipeRefreshLayout        android:id="@+id/swipe_refresh"        android:layout_width="match_parent"        android:layout_height="match_parent" >        <ListView            android:id="@+id/listview"            android:layout_width="match_parent"            android:layout_height="match_parent" >        </ListView>    </android.support.v4.widget.SwipeRefreshLayout>

3.在java檔案中使用。

/** * 首頁 * @author w.w */public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {/** * 給ListView添加下拉重新整理 */private SwipeRefreshLayout swipeLayout;/** * ListView */private ListView listView;/** * ListView適配器 */private ListViewAdapter adapter;private List<ItemInfo> infoList;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);swipeLayout = (SwipeRefreshLayout) this.findViewById(R.id.swipe_refresh);swipeLayout.setOnRefreshListener(this);// 頂部重新整理的樣式swipeLayout.setColorScheme(android.R.color.holo_red_light, android.R.color.holo_green_light,android.R.color.holo_blue_bright, android.R.color.holo_orange_light);infoList = new ArrayList<ItemInfo>();ItemInfo info = new ItemInfo();info.setName("coin");infoList.add(info);listView = (ListView) this.findViewById(R.id.listview);adapter = new ListViewAdapter(this, infoList);listView.setAdapter(adapter);}public void onRefresh() {new Handler().postDelayed(new Runnable() {public void run() {swipeLayout.setRefreshing(false);ItemInfo info = new ItemInfo();info.setName("coin-refresh");infoList.add(info);adapter.notifyDataSetChanged();}}, 500);}}

demo:http://download.csdn.net/detail/xue_wei_love/7135315

聯繫我們

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