下拉刷新SwipeRefreshLayout源码-创新互联
API doc:http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
成都创新互联公司主营麒麟网站建设的网络公司,主营网站建设方案,重庆App定制开发,麒麟h5小程序制作搭建,麒麟网站营销推广欢迎麒麟等地区企业咨询Google在support v4 19.1版本推出了一个下拉刷新组件SwipeRefreshLayout,使用起来方便,效果优美,但要注意的是其布局中只能有一个直接子布局。使用步骤如下:
1.在xml中,加载android.support.v4.widget.SwipeRefreshLayout
2.使用
package com.example.testswiperefreshlayout; import android.os.Bundle; import android.os.Handler; import android.annotation.SuppressLint; import android.app.Activity; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; public class MainActivity extends Activity implements OnRefreshListener { private SwipeRefreshLayout mSwipeRefreshLayout; private ListView mList; @SuppressLint("InlinedApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mList = (ListView) findViewById(R.id.list); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.layout_containter); mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); mSwipeRefreshLayout.setOnRefreshListener(this); } @Override public void onRefresh() { new Handler().postDelayed(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(false); mList.setAdapter(new MyAdapter()); } }, 5000); } class MyAdapter extends BaseAdapter { @Override public int getCount() { return 10; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { View inflate = null; TextView tvItem = null; if (convertView == null) { inflate = getLayoutInflater().inflate(R.layout.listview_item, null); tvItem = (TextView) inflate.findViewById(R.id.tv_item); inflate.setTag(tvItem); } else { inflate = convertView; tvItem = (TextView) inflate.getTag(); } tvItem.setText("下拉刷新item"+position); return inflate; } } }
×××地址:http://download.csdn.net/detail/dennisruan/9433027
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站名称:下拉刷新SwipeRefreshLayout源码-创新互联
网页地址:http://azwzsj.com/article/phdpj.html