标签:
@XStreamAlias("oschina") public class MyDatas { public class Mynewslist { @XStreamImplicit(itemFieldName="news") private List<MyNews> news;
package com.example.fragment; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.example.adapter.CopyOfMybaseadpter; import com.example.adapter.Mybaseadpter; import com.example.bean.Mmsupper; import com.example.bean.Myblog; import com.example.view.XListView; import com.example.view.XListView.IXListViewListener; import com.example.vo.Mynews; import com.example.vo.Super; import com.example.yk06.R; import com.lidroid.xutils.HttpUtils; import com.lidroid.xutils.exception.HttpException; import com.lidroid.xutils.http.ResponseInfo; import com.lidroid.xutils.http.callback.RequestCallBack; import com.lidroid.xutils.http.client.HttpRequest.HttpMethod; import com.thoughtworks.xstream.XStream; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class F1 extends Fragment implements IXListViewListener{ private XListView listView; String url; int mm; private Mybaseadpter mybaseadpter; private CopyOfMybaseadpter mybaseadpte; int count=1; private List<Mynews> l=new ArrayList<Mynews>(); private List<Myblog> li=new ArrayList<Myblog>(); public F1(String url, int mm) { super(); this.url = url; this.mm = mm; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.activity_f1, null); listView = (XListView) view.findViewById(R.id.lsitview); listView.setPullLoadEnable(true); listView.setPullRefreshEnable(true); listView.setXListViewListener(this); init(); return view; } private void init() { // TODO Auto-generated method stub HttpUtils utils=new HttpUtils(); utils.send(HttpMethod.GET, url+count++, new RequestCallBack<String>() { @Override public void onFailure(HttpException arg0, String arg1) { // TODO Auto-generated method stub } @Override public void onSuccess(ResponseInfo<String> arg0) { // TODO Auto-generated method stub String ss=arg0.result; XStream stream=new XStream(); if (mm==0||mm==1) { stream.processAnnotations(Super.class); Super super1=(Super) stream.fromXML(ss); List<Mynews> ll=super1.getNewslist().getNews(); l.addAll(0,ll); mybaseadpter = new Mybaseadpter(l, getActivity()); listView.setAdapter(mybaseadpter); } if(mm==2||mm==3){ stream.processAnnotations(Mmsupper.class); Mmsupper super1=(Mmsupper) stream.fromXML(ss); List<Myblog> ll=super1.getBlogs().getBlog(); li.addAll(0,ll); System.out.println(li.toString()); mybaseadpte= new CopyOfMybaseadpter(li, getActivity()); listView.setAdapter(mybaseadpte); } } }); } private void onLoad() { // TODO Auto-generated method stub listView.stopRefresh(); listView.stopLoadMore(); // 设置日期格式 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 获取当前系统时间 String nowTime = df.format(new Date(System.currentTimeMillis())); // 释放时提示正在刷新时的当前时间 listView.setRefreshTime(nowTime); } @Override public void onRefresh() { // TODO Auto-generated method stub init(); onLoad(); } @Override public void onLoadMore() { // TODO Auto-generated method stub HttpUtils utils=new HttpUtils(); utils.send(HttpMethod.GET, url+count++, new RequestCallBack<String>() { @Override public void onFailure(HttpException arg0, String arg1) { // TODO Auto-generated method stub } @Override public void onSuccess(ResponseInfo<String> arg0) { // TODO Auto-generated method stub String ss=arg0.result; XStream stream=new XStream(); if (mm==0||mm==1) { stream.processAnnotations(Super.class); Super super1=(Super) stream.fromXML(ss); List<Mynews> ll=super1.getNewslist().getNews(); l.addAll(ll); mybaseadpter.notifyDataSetChanged(); } if (mm==2||mm==3){ stream.processAnnotations(Mmsupper.class); Mmsupper super1=(Mmsupper) stream.fromXML(ss); List<Myblog> ll=super1.getBlogs().getBlog(); li.addAll(ll); mybaseadpte.notifyDataSetChanged(); } } }); onLoad(); } }
标签:
原文地址:http://www.cnblogs.com/yr520/p/5355196.html