android —— 自定义控件 最简单下拉刷新,Google最新(可刷新任何控件)
16lz
2021-12-04
main_activity.xml代码:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipe_container" android:layout_width="match_parent" android:layout_height="match_parent" > android:id="@+id/swipe_container" android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent" > </ListView></android.support.v4.widget.SwipeRefreshLayout> MainActivity.java /** Created by Storm Zhang, Mar 31, 2014.*/package com.storm.swiperefreshlayoutdemo;import java.util.ArrayList;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.support.v4.widget.SwipeRefreshLayout;import android.widget.ListView;public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {private SwipeRefreshLayout swipeLayout;private ListView listView;private ListViewAdapter adapter;private ArrayList<SoftwareClassificationInfo> list;@overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); swipeLayout.setOnRefreshListener(this); swipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); list = new ArrayList<SoftwareClassificationInfo>(); list.add(new SoftwareClassificationInfo(1, "asdas")); listView = (ListView) findViewById(R.id.list); adapter = new ListViewAdapter(this, list); listView.setAdapter(adapter);}@overridepublic void onRefresh() { new Handler().postDelayed(new Runnable() { public void run() { swipeLayout.setRefreshing(false); list.add(new SoftwareClassificationInfo(2, "ass")); adapter.notifyDataSetChanged(); } }, 1000); }} Demo如下,感谢大家支持。 |
-
110023izlpdpesua6jhawd[1].jpg
更多相关文章
- android游戏开发项目实战——数独
- ch017 Android(安卓)样式与主题
- android Activity 变成Dialog的方法
- ch017 Android(安卓)样式与主题
- 引用 Android内核和驱动篇-Android内核介绍
- Android(安卓)Launcher一些资源
- android:maxLines和android:ellipsize
- android 解决password过时
- android:ellipsize的使用