使用Google API 下拉刷新或者增加数据 SwipeRefreshLayout
2016-03-15 18:01
441 查看
贴出布局代码:
根据我的不完全实验 SwipeRefreshLayout 内可以使用所有控件,但是前提是必须在不能点击的控件上 写上这个 android:clickable=“true” ,不然会有些问题。虽然数据依然能加载出来但是加载图标就会闪现(可以随意尝试)
使用这个 SwipeRefreshLayout 必须实现这个接口:
MainAcitivity
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/id_swipe_ly" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:clickable="true"> <TextView android:id="@+id/id_listview" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮"/> </LinearLayout> </android.support.v4.widget.SwipeRefreshLayout>
根据我的不完全实验 SwipeRefreshLayout 内可以使用所有控件,但是前提是必须在不能点击的控件上 写上这个 android:clickable=“true” ,不然会有些问题。虽然数据依然能加载出来但是加载图标就会闪现(可以随意尝试)
使用这个 SwipeRefreshLayout 必须实现这个接口:
public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener 然后会自动生成它的一个方法:
public void onRefresh() { } 可以在这里面写你的一系列操作,但是不建议写耗时的操作,可以写一个Handler 来接收信息 并加载信息。 全部代码: 布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/id_swipe_ly" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:clickable="true"> <TextView android:id="@+id/id_listview" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮"/> </LinearLayout> </android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
MainAcitivity
public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener { private static final int REFRESH_COMPLETE = 0X110; private SwipeRefreshLayout mSwipeLayout; private TextView mListView; private Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case REFRESH_COMPLETE: mListView.setText("猪猪侠"); mSwipeLayout.setRefreshing(false); break; } } ; }; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mListView = (TextView) findViewById(R.id.id_listview); mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.id_swipe_ly); mSwipeLayout.setOnRefreshListener(this); mSwipeLayout.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); } public void onRefresh() { mHandler.sendEmptyMessageDelayed(REFRESH_COMPLETE, 2000); } }
至此就可以完成了 一个简单的刷新!
相关文章推荐
- CodeForces 367A-Sereja and Algorithm【规律】
- Go语言核心之美 1.4-包和文件
- Django中间件
- Django URL 分发
- AlphaGo最终局战胜李世石
- AlphaGo最终局战胜李世石
- Windows下面替换命令实现,最新修复一个BUG
- mongo集群分片如何添加认证密码
- 去掉Googl默认界面的logo下面的尴尬的文字,对面的菇凉请看过来!!!
- django filter 中使用 or (django中Q)
- 当View为GONE状态时获取View的宽高
- CodeForces#5A. Chat Server's Outgoing Traffic
- AlphaGo:黑色方碑?
- lightoj 1030 Discovering Gold 概率dp求期望
- mongo 删除内嵌数组元素
- Go语言核心之美 1.3-赋值及类型声明篇
- Django路由系统
- 科普:alphago是什么
- 【Google Earth】使用GPS数据gpx创建航迹
- [Canvas绘图] 第34节 藏图阁(14) AlphaGo与李世石的围棋大战之第四局