首页 新闻 会员 周边 捐助

安卓4.0访问网络线程问题

0
悬赏园豆:100 [待解决问题]
    public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.activity_main);  
           lView=(ListView)findViewById(R.id.listview);
           resultView=(TextView)findViewById(R.id.t);
           getRemoteInfo("1");
        }
        


public void getRemoteInfo(String phoneSec) {
       new Thread(new Runnable() {  
            
          @Override  
          public void run() {  

   // 命名空间
   String nameSpace = "http://sp.qwsy.com/";

   // 调用的方法名称
   String methodName = "GetBookInfo";

   // EndPoint
   String endPoint = "http://sp.qwsy.com/book.asmx";

   // SOAP Action
   String soapAction = "http://sp.qwsy.com/GetBookInfo";
   //验证豹纹头
   Element[] header = new Element[1];
   header[0] = new Element().createElement(nameSpace, "MyCustomSoapHeader"); 

   Element Spid = new Element().createElement(nameSpace, "Spid");
   Spid.addChild(Node.TEXT, "10001");
   header[0].addChild(Node.ELEMENT, Spid);
   Element Qtime = new Element().createElement(nameSpace, "Qtime");
   Qtime.addChild(Node.TEXT, "20130510144000");
   header[0].addChild(Node.ELEMENT, Qtime); 
   Element Sign = new Element().createElement(nameSpace, "Sign");
   Sign.addChild(Node.TEXT, "30fc3bfd81120422561fd849efc44853");
   header[0].addChild(Node.ELEMENT, Sign); 
   // 指定WebService的命名空间和调用的方法名
   SoapObject rpc = new SoapObject(nameSpace, methodName);
   Log.i("top",rpc.toString());
   // 设置需调用WebService接口需要传入的两个参数mobileCode、userId,不可以随便写,必须和提供的参数名相同
   //rpc.addProperty("mobileCode", "15975505657");
   //rpc.addProperty("userId", "");
   rpc.addProperty("bookID","41");

   // 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
     SoapEnvelope.VER11);
  
   envelope.bodyOut = rpc;
 
   // 设置是否调用的是dotNet开发的WebService
   envelope.dotNet = true;
   envelope.headerOut = header; 
   // 等价于envelope.bodyOut = rpc;
   envelope.setOutputSoapObject(rpc);
   HttpTransportSE transport = new HttpTransportSE(endPoint);

   try {
    // 调用WebService
    transport.call(soapAction, envelope);
   } catch (Exception e) {

    e.printStackTrace();
   }

   // 获取返回的数据
   SoapObject object = (SoapObject) envelope.bodyIn;
  
   // 获取返回的结果bookpic
    String result = ((SoapObject) ((SoapObject) object.getProperty(0)).getProperty(0)).getProperty("zzjs").toString();
    String name = ((SoapObject) ((SoapObject) object.getProperty(0)).getProperty(0)).getProperty("bookname").toString();
    String pic = ((SoapObject) ((SoapObject) object.getProperty(0)).getProperty(0)).getProperty("bookpic").toString();
   Message message = handler.obtainMessage();  
   
 
  
   Log.i("end",result);
     ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();  
     for(int i=0;i<100;i++)  
     {  
         HashMap<String, Object> map = new HashMap<String, Object>();  
         map.put("ItemImage",pic);//图像资源的ID  
         map.put("ItemTitle",name);  
         map.put("ItemText",result);  
         listItem.add(map);  
     }  
     //生成适配器的Item和动态数组对应的元素  
     MySimpleAdapter  listItemAdapter = new MySimpleAdapter (MainActivity.this,listItem,//数据源   
         R.layout.list_item,//ListItem的XML实现  
         //动态数组与ImageItem对应的子项          
         new String[] {"ItemImage","ItemTitle", "ItemText"},   
         //ImageItem的XML文件里面的一个ImageView,两个TextView ID  
         new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.ItemText}  
     );  
      
     //添加并且显示  
     message.obj=listItemAdapter;
     handler.sendMessage(message);
     //点击事件
     lView.setOnItemClickListener(new OnItemClickListener() {
        @Override  
         public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,  
                 long arg3) {  
             setTitle("点击第"+arg2+"个项目");  
         }  
    });
  
  }
       }).start();
    
}

private Handler handler = new Handler(){  
      public void handleMessage(android.os.Message msg) {  
          // 将WebService得到的结果返回给TextView          
           lView.setAdapter((ListAdapter) msg.obj); 
  
      }; 
  };  

}

这个不是开线程了吗?为什么真机4.0还不行啊.模拟器2.2就可以

逝去的光影的主页 逝去的光影 | 初学一级 | 园豆:13
提问于:2013-05-21 12:03
< >
分享
所有回答(3)
0
@@@一统@@@ | 园豆:1551 (小虾三级) | 2013-05-21 12:33
-1

@@@一统@@@又来抢分了、

丫的 | 园豆:1575 (小虾三级) | 2013-05-21 13:06
0

试下这种方式:

    Bundle bundle = new Bundle();
                    bundle.putString("xml", arg0);
                    bundle.putString("money", arg1);
                    bundle.putString("paychannel", arg2);
                    Message msg = handler.obtainMessage(R.id.invoke_plug_in);
                    msg.setData(bundle);
                    msg.sendToTarget();

wlz0815 | 园豆:587 (小虾三级) | 2013-05-21 14:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册