当前位置: 代码迷 >> Android >> SwipeRefreshLayout.setRefreshing(false) 停不下来 肿么办啊该怎么解决
  详细解决方案

SwipeRefreshLayout.setRefreshing(false) 停不下来 肿么办啊该怎么解决

热度:204   发布时间:2016-04-28 03:47:25.0
SwipeRefreshLayout.setRefreshing(false) 停不下来 肿么办啊!
直接扔代码吧


package cn.lianfa.elec.SceneManagement;

import java.io.File;
import java.util.ArrayList;

import cn.lianfa.elec.R;
import android.R.anim;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ListFragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class SceneAllPicFragment extends ListFragment {
String RootFilePath = Environment.getExternalStorageDirectory().getPath()
+ "/pdpic/image";

ArrayList<ScenePicture> listItem = new ArrayList<ScenePicture>(); // ListView的数据源

SwipeRefreshLayout swipelayout;

@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

// 添加SwipeRefreshLayout
View layout = super.onCreateView(inflater, container,
savedInstanceState);
swipelayout = new SwipeRefreshLayout(getActivity());
swipelayout.addView(layout);
// swipelayout.setOverScrollMode(SwipeRefreshLayout.OVER_SCROLL_NEVER);

// swipelayout.setColorScheme(android.R.color.darker_gray,
// android.R.color.white, android.R.color.darker_gray,
// android.R.color.white);
swipelayout.setOnRefreshListener(new OnRefreshListener() {

@Override
public void onRefresh() {
// TODO Auto-generated method stub
System.out.println("刷新开始!!!");
if (swipelayout.isRefreshing()!=true)
{
initData();
}
System.out.println("刷新结束!!!");
}
});

// TODO Auto-generated method stub
if (listItem.size() == 0) {
initData();
}
;
AllPicBaseAdapter Allpicbsadptr = new AllPicBaseAdapter(getActivity()
.getBaseContext(), R.layout.all_picinfo_item, listItem);
setListAdapter(Allpicbsadptr);

return swipelayout;

}

private void initData() {
// TODO Auto-generated method stub
// 将所有文件存入list中
Runnable run=new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
swipelayout.setRefreshing(true);
listItem.clear();
File f = new File(RootFilePath);
File[] files = f.listFiles();// 列出所有文件
if (files != null) {
for (int i = 0; i <= files.length - 1; i++) {
File file = files[i];
System.out.println(file.toURI().getPath());
ScenePicture pic = new ScenePicture(android.net.Uri.parse(file
.toURI().getPath()));
listItem.add(pic);
}
}
swipelayout.setRefreshing(false);
}
};
new Thread(run).start();

}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
}

------解决思路----------------------
 if (swipelayout.isRefreshing()!=true)
                {
                initData();
                }
这个错了,这句你放在监听里,监听是刷新的时候触发的,所以这个时候swipelayout.isRefreshing()就是true的,根本就不执行initData(),所以就没有执行swipelayout.setRefreshing(false);
  相关解决方案