swipRefresh在fragment中使用
来源:互联网 发布:sql三大部分 编辑:程序博客网 时间:2024/06/09 20:19
首先在xml布局中声明swiperefresh控件,直接上代码:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/swipeRefresh" android:orientation="vertical" tools:context="com.example.administrator.ordersystem.fragment.StayOperaterFragment"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.Toolbar android:background="#309cfc" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/title_number" android:textSize="20dp" android:textColor="#fff" android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:text="待操作"/> </android.support.v7.widget.Toolbar> <ListView android:id="@+id/operator_listview" android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> </LinearLayout> </ScrollView></android.support.v4.widget.SwipeRefreshLayout>
然后在fragment代码中:
public class StayOperaterFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener{ private ListView listView; private List<ListInfoBean> list; private String strNO,strName; private ListInfoAdapter adapter; private TextView title_number; private SwipeRefreshLayout swipeRefresh; @Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_stay_operater, container, false); listView = (ListView) view.findViewById(R.id.operator_listview); title_number = (TextView) view.findViewById(R.id.title_number); swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefresh); init(); //设置刷新出现的位置 // swipeRefresh.setProgressViewEndTarget(false, 200);//绑定监听 swipeRefresh.setOnRefreshListener(this);//设置颜色 swipeRefresh.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light); swipeRefresh.setDistanceToTriggerSync(50); @Override public void onRefresh() { list.clear(); init(); new Handler().postDelayed(new Runnable() { @Override public void run() { swipeRefresh.setRefreshing(false); } },4000); }基本就是这样的,就可以实现下拉刷新了,刷新数据可以在onRerfresh方法中
1 0
- swipRefresh在fragment中使用
- 在Fragment中使用GestureDetector
- 在Fragment中使用Menu
- Fragment在xml中使用
- 在fragment中使用onActivityResult
- 在Fragment中使用Listview
- 在Fragment嵌套Fragment使用中,出现第二次使用空白
- 在Activity,Fragment,嵌套Fragment中使用ToolBar
- 【android】在fragment中使用option menu
- 在Fragment中使用Loader机制介绍
- ViewPagerInFragment 在Fragment中使用ViewPager
- 在Fragment中使用百度地图
- 在ViewPager中使用Fragment嵌套问题
- 如何在Fragment中使用findViewById呢?
- 在Fragment中使用Gridview+Spinner
- DrawerLayout不能放在fragment中使用
- 在Fragment中如何使用Toolbar
- Android在Fragment中使用Tab
- 更多形态学处理--开运算、闭运算、
- 面试之xml解析方式及优缺点
- linux 中断机制
- POJ1905[Expanding Rods]题解
- 十大编程算法助程序员走上高手之路
- swipRefresh在fragment中使用
- 去掉CSDN-markdown编辑器的上传图片里面的水印
- 皮皮学Web第二弹——Servlet
- 语言模型(N-Gram)
- Linux下配置静态IP地址,设置DNS和主机名
- HPUOJ---2017寒假作业--专题-1/L-Raising Modulo Numbers(提高模数)
- CSS3:nth-child的用法
- FICO年结完全手册
- 常用数学公式推导及概念