private ProgressDialog dialog;
private XListView collectlist;
private ArrayList<HashMap<String, Object>> collectArr;
private int page = 1;
private int index = -1;
implements IXListViewListener
collectlist = (XListView)findViewById(R.id.collectlist);
collectlist.setPullRefreshEnable(true);
collectlist.setPullLoadEnable(true);
collectlist.setXListViewListener(this);
private Boolean isfirstlist = false;
public void initvlist() {
adapter = new LinGanBaseAdapter(ShouCangActivity.this, collectArr,options);
collectlist.setAdapter(adapter);
collectlist.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
Intent i = new Intent(ShouCangActivity.this, LinGanDetailsActivity.class);
i.putExtra("ideaid", collectArr.get(position-1).get("id").toString());
startActivity(i);
}
});
collectlist.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
index = position - 1;
// PopupWindows = new PopupWindows(getActivity(), collectlist);
return false;
}
});
isfirstlist = true;
}
@SuppressLint("HandlerLeak")
public void handleMessage(Message msg) {
collectlist.stopRefresh();
collectlist.stopLoadMore();
SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy-MM-dd HH:mm");
Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
String nowdatestr = formatter.format(curDate);
collectlist.setRefreshTime(nowdatestr);
switch (msg.what) {
case 0:
String httpstr = urlclient.getInput();
if (httpstr == null || httpstr.equals("")) {
return;
}
String[] key={"id","date","content","is_read","fromuser","touser"};
if (page == 1) {
if (collectArr != null) {
collectArr.clear();
}
collectArr = new ArrayList<HashMap<String, Object>>();
}
collectArr=json.getnotitleJSONArray(collectArr, httpstr, key);
if (collectArr.size() == 0) {
return;
}
if (page == 1) {
initvlist();
} else {
adapter = new SiXinBaseDtAdapter(SiXinDetailActivity.this, collectArr);
collectlist.setAdapter(adapter);
}
break;
case 1:
break;
}
super.handleMessage(msg);
}
public void onRefresh() {// 刷新
// TODO Auto-generated method stub
if (isfirstlist == true) {
collectlist.stopRefresh();
collectlist.stopLoadMore();
isfirstlist = false;
} else {
page = 1;
if (collectArr != null) {
collectArr.clear();
}
collectArr = new ArrayList<HashMap<String, Object>>();
getCollectData(UrlVO.ShouCang_Url);
}
}
public void onLoadMore() {// 加载更多
// TODO Auto-generated method stub
page += 1;
getCollectData(UrlVO.ShouCang_Url);
}
<com.gazrey.listcontrol.XListView
android:id="@+id/collectlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/titlebar"
android:cacheColorHint="#00000000"
android:divider="@null"
android:fadingEdge="none"
android:listSelector="@android:color/transparent"
android:scrollbars="none" >
</com.gazrey.listcontrol.XListView>
Android下拉刷新,上拉加载
最新推荐文章于 2022-03-18 15:23:14 发布