zoukankan      html  css  js  c++  java
  • XUtils

    //HttpUtils实例化对象
         HttpUtils http = new HttpUtils();
           /*
                    *发送请求send(HttpMethod method, String url, RequestCallBack<T> callBack)
                 * method请求方式
                  * url请求地址
                  *RequestCallBack <String>请求完后的回调监听String是请求完后你想让他返回什么类型的
                 */
               http.send(HttpRequest.HttpMethod.GET, urlPath,new RequestCallBack<String>() {
                           @Override
                           public void onLoading(long total, long current, boolean isUploading) {
                             }
                           @Override
                            public void onSuccess(ResponseInfo<String> responseInfo) {
                              String s = responseInfo.result;
                              //    System.out.println(s);
                                  try {
                                    //判断,如果有数据先清空
                                    if (STATE_3 == STATE_1) {
                                        news .clear();
                                    }
                                    News newss=null;
                                    XmlPullParser parser=Xml.newPullParser();
                                    ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(s.getBytes());
                                    parser.setInput(byteArrayInputStream, "utf-8");
                                    int eventType=parser.getEventType();
                                    while (eventType!=XmlPullParser.END_DOCUMENT) {
                                        String name=parser.getName();
                                        switch (eventType) {
                                        case XmlPullParser.START_TAG:
                                            if (name.equals("news")) {
                                                newss=new News();
                                            }else if (name.equals("title")) {
                                                String title=parser.nextText();
                                                newss.setTitle(title);
                                            }
                                            else if (name.equals("body")) {
                                                String body=parser.nextText();
                                                newss.setBody(body);
                                            }
                                            else if (name.equals("commentCount")) {
                                                String commentCount=parser.nextText();
                                                newss.setCommentCount(commentCount);
                                            }
                                            else if (name.equals("author")) {
                                                String author=parser.nextText();
                                                newss.setAuthor(author);
                                            }else if (name.equals("pubDate")) {
                                                String pubDate=parser.nextText();
                                                newss.setPubDate(pubDate);
                                                
                                            }
                                            break;
                                        case XmlPullParser.END_TAG:
                                            
                                            if (name.equals("news")) {
                                                news.add(newss);
                                                
                                                //更新适配器
                                                if (adapter == null) {
                                                   adapter = new MyAdapter(news,getActivity());
                                                   lv.setAdapter(adapter);
                                                  } else {
                                                    adapter .notifyDataSetChanged();
                                                         }
                                                    load();
                                            }
                                            break;

                                        default:
                                            break;
                                        }
                                        eventType=parser.next();                
                                    }
                                } catch (XmlPullParserException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                     @Override
                            public void onStart() {
                         }
                           @Override
                           public void onFailure(HttpException error, String msg) {
                             }
                         });

  • 相关阅读:
    移动端获取屏幕的宽度,根据屏幕大小动态设置html的rem字体大小
    解析CSS3伪类选择器nth-of-type和nth-child的用法,以及两者的区别
    移动端的1px的解决方案
    Vue中import from的来源:省略后缀与加载文件夹
    flex布局
    前端开发人员快速创建本地服务器
    centos6.5Xen4.2安装
    centos6.5kvm虚拟化安装部署
    CentOS搭建svn服务器支持https访问
    CentOS6.5搭建LNMP
  • 原文地址:https://www.cnblogs.com/changyiqiang/p/5717278.html
Copyright © 2011-2022 走看看