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就可以
试下这种方式:
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();