如果不是分页的链接需要添加
private boolean isPull =false;
//判断需要改为
if (isPull) {
isPull = !isPull;
goodsList.clear();
}
刷新要改为
isPull=true;加载删掉
/没有分页的
private String path ="http://172.17.8.100/mobile/exam/findNewList";
// private int page = 1;
private PullAdapter pullAadpder;
private boolean isPull =false;
private PullToRefreshListView pullListView;
private HttpUtils httpUtils;
private List<Goods.ResultBean.DataBean> goodsList = new ArrayList <> ();
//侧滑
private DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
drawerLayout = findViewById (R.id.dw);
pullListView = findViewById (R.id.pull);
//数据解析
setDataJson();
pullListView.setOnItemClickListener (new AdapterView.OnItemClickListener () {
@Override
public void onItemClick(AdapterView <?> parent, View view, int position, long id) {
Goods.ResultBean.DataBean bean = (Goods.ResultBean.DataBean) parent.getAdapter ().getItem (position);
Intent intent = new Intent (MainActivity.this,WebActivity.class);
intent.putExtra ("url",bean.getUrl ());
startActivity (intent);
}
});
}
private void setDataJson() {
httpUtils = HttpUtils.getInstance ();
httpUtils.getDataFromServer (path);
httpUtils.setNetCallback (new HttpUtils.NetCallback () {
@Override
public void onSuccess(String result) {
Gson gson = new Gson ();
Goods goods = gson.fromJson (result, Goods.class);
if (isPull) {
isPull = !isPull;
goodsList.clear();
}
goodsList.addAll (goods.getResult ().getData ());
pullAadpder.notifyDataSetChanged ();
}
});
pullAadpder = new PullAdapter (goodsList, this);
pullListView.setAdapter (pullAadpder);
pullListView.setMode (PullToRefreshExpandableListView.Mode.BOTH);
pullListView.setOnRefreshListener (new PullToRefreshBase.OnRefreshListener2 <ListView> () {
@Override
public void onPullDownToRefresh(PullToRefreshBase <ListView> refreshView) {
//刷新
isPull=true;
httpUtils.getDataFromServer (path);
pullListView.postDelayed (new Runnable () {
@Override
public void run() {
pullListView.onRefreshComplete ();
}
}, 1000);
}
@Override
public void onPullUpToRefresh(PullToRefreshBase <ListView> refreshView) {
//加载
httpUtils.getDataFromServer (path);
pullListView.postDelayed (new Runnable () {
@Override
public void run() {
pullListView.onRefreshComplete ();
}
}, 1000);
}
});
}
}