<LinearLayout 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:orientation="vertical"> <!-- 我们添加了一个属性:ptr:ptrMode="both" ,意思:上拉和下拉都支持。 可选值为:disabled(禁用下拉刷新),pullFromStart(仅支持下拉刷新), pullFromEnd(仅支持上拉刷新),both(二者都支持),manualOnly(只允许手动触发) --> <!-- ptr:ptrAnimationStyle="rotate" FlipLoadingLayout为iOS风格的箭头颠倒的刷新动画 ptr:ptrAnimationStyle="flip" RotateLoadingLayout为android风格的图片旋转动画 --> <com.ptrflv.www.pulltorefreshlistview.PullToRefreshListView xmlns:ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/pull_to_refresh_listview" android:layout_width="wrap_content" android:layout_height="wrap_content" ptr:ptrMode="both" ptr:ptrAnimationStyle="flip" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- 上拉刷新 --> <!-- …代表三个点 ... --> <string name="pull_to_refresh_pull_label">向下拉刷新…</string> <string name="pull_to_refresh_release_label">松开更新…</string> <string name="pull_to_refresh_refreshing_label">正在加载…</string> <!-- 下拉加载更多 --> <string name="pull_to_refresh_from_bottom_pull_label">向下拉加载更多…</string> <string name="pull_to_refresh_from_bottom_release_label">松开加载更多…</string> <string name="pull_to_refresh_from_bottom_refreshing_label">正在加载…</string> </resources>
public class MainActivity extends Activity {
private PullToRefreshListView pullToRefreshListView;
//adapter的数据源
private List<String> numList=new ArrayList<String>();
private ArrayAdapter<String> arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pullToRefreshListView=(PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview);
//初始化数据
for(int x=0;x<18;x++){
numList.add(""+x);
}
arrayAdapter = new ArrayAdapter<String>(this, R.layout.item_listview,R.id.textview,numList);
pullToRefreshListView.setAdapter(arrayAdapter);
//设定刷新监听
pullToRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
// 显示最后更新的时间
refreshView.getLoadingLayoutProxy() .setLastUpdatedLabel(label);
//代表下拉刷新
if(refreshView.getHeaderLayout().isShown()){
new Thread(){
public void run() {
try {
sleep(1000);
handler.sendEmptyMessage(99);
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();
}
//代表下拉刷新
if(refreshView.getFooterLayout().isShown()){
new Thread(){
public void run() {
try {
sleep(1000);
handler.sendEmptyMessage(98);
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();
}
}
});
}
private Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) {
if(msg.what==99){
numList.add(0, "英雄联盟");
arrayAdapter.notifyDataSetChanged();
//关闭刷新的动画
pullToRefreshListView.onRefreshComplete();
}
if(msg.what==98){
numList.add(numList.size(), "魔兽世界");
arrayAdapter.notifyDataSetChanged();
//关闭刷新的动画
pullToRefreshListView.onRefreshComplete();
}
};
};
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有