android hander 线程用法

		@Override
		public void onClick(View v) {
			lsh = "576";
			startdate = setstart_date.getText().toString();
			enddate = setend_date.getText().toString();
			btnLoginContext = v.getContext();
			HandlerThread handlerThread = new HandlerThread("handlerThread");
			handlerThread.start();// 启新线程
			MyHandler myHandler = new MyHandler(handlerThread.getLooper());// 建消息队列的处理器(新线程)
			Message msg = myHandler.obtainMessage();// 绑定自定义的处理器
			Bundle bundle = new Bundle();
			bundle.putString("startdate", startdate);
			bundle.putString("enddate", enddate);
			bundle.putString("lsh", lsh);
			msg.setData(bundle);
			msg.sendToTarget();
		}		
@Override
		public void handleMessage(Message msg) {
			try {
				super.handleMessage(msg);

				Bundle bundle = msg.getData();
				if (bundle == null)
					return;
				String result = "";
				StringBuilder str = new StringBuilder();
				str.append("<condition><ksrqsj>" +  bundle.get("startdate").toString()+ "</ksrqsj>");
				str.append("<jsrqsj>" +  bundle.get("enddate").toString()+ "</jsrqsj>");
				str.append("<lsh>" +  bundle.get("lsh").toString()+ "</lsh></condition>");

				RequireParams params = new RequireParams();
				params.setMethodName("GetNurseTableinfoPag");
				WebServiceInvoker invoker = new WebServiceInvoker();
				invoker.setParams(params);
				//设置参数
				SoapObject request = invoker.getRequestInstance();
				request.addProperty("condition", str.toString());
				request.addProperty("recBegin", 0);
				request.addProperty("recEnd", 10);
				result = invoker.invokeWS(request).getProperty(0).toString();

				if (result.indexOf("error") >= 0) {
					showMyDialog(btnLoginContext, result);
					return;
				} else {
					List<Map<String, Object>> myNurseInfos = null;
					myNurseInfos = NurseInfo.getNurseInfo(result, "UTF-8");
					//查询成功
					Intent intent = new Intent();  
					Bundle mybundle = new Bundle();
			        final SerializableMaplist myMap=new SerializableMaplist();
			        myMap.setMap(myNurseInfos);
					mybundle.putSerializable("listdata", myMap);
	                intent.putExtras(mybundle);
	                intent.setClass(getActivity(), NursingPageQuery.class);  
	                startActivity(intent);  
				}
			} catch (Exception e) {
				Log.e(TAG, Log.getStackTraceString(e));
				Toast.makeText(getActivity(),"错误:"+ Log.getStackTraceString(e),Toast.LENGTH_LONG).show();
			}

  

android hander 线程用法,布布扣,bubuko.com

android hander 线程用法

上一篇:5、Android-跨程序共享数据--内容提供器


下一篇:Android:Toast简单消息提示框