swiperefreshlayout实现下拉小球式的刷新,供大家参考,具体内容如下
布局文件:
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
android:id="@+id/swipeRefreshLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
MainActivity:
public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener{
private static final int REFRESH_STATUS =0;
private ListView myListView;
private SwipeRefreshLayout mySwipeRefreshLayout;
private ArrayAdapter listAdapter;
private List listIDE = new ArrayList(Arrays.asList("Visual Studio","Android Studio","Eclipse","Xcode"));
private Handler refreshHandler = new Handler()
{
public void handleMessage(android.os.Message msg)
{
switch (msg.what)
{
case REFRESH_STATUS:
listIDE.removeAll(listIDE);
listIDE.addAll(Arrays.asList("C#","Java","C++","Object-C"));
listAdapter.notifyDataSetChanged();
mySwipeRefreshLayout.setRefreshing(false);
break;
}
};
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myListView = (ListView) findViewById(R.id.listView);
mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
mySwipeRefreshLayout.setOnRefreshListener(this);
mySwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,android.R.color.holo_green_light,android.R.color.holo_orange_light,android.R.color.holo_red_light);
listAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,listIDE);
myListView.setAdapter(listAdapter);
}
@Override
public void onRefresh() {
refreshHandler.sendEmptyMessageDelayed(REFRESH_STATUS,1500);
}
}
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
小编个人微信号 jb51ccc
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!