編輯:關於Android編程
public void DoTuiKuDJ(final String dtZzjl, final String dtRkdmx, final String dtRkd) {//這裡的三個String都是將類放到List當中,然後將List轉化成XML的形式來傳遞的,List轉化XML的代碼下面會給出 new Webservice(context, handler, TuiKuDJ, true, null, null, null) { @Override public void addProgerty(SoapObject rpc) { // TODO Auto-generated method stub method = 2; rpc.addProperty(dtZzjl, dtZzjl); rpc.addProperty(dtRkdmx, dtRkdmx); rpc.addProperty(dtRkd, dtRkd); } }; } /** * 數據傳回來處理 */ private Handler handler = new Handler() { @SuppressWarnings(unchecked) public void handleMessage(android.os.Message msg) { switch (msg.what) { case 0: if (method == 1) { zzjl = (ListWebService類:) (msg.obj);//msg.obj為傳回來的數據 tuiKuFragment.DealZzjl(); break; } break; break; } }; };
/** * web service通信類 * @author Administrator 上傳時要分int,String 而接受數據射計類都要是String */ public abstract class Webservice { public static final String NAMESPACE = http://tempuri.org/; // WebService地址 private String URL; /** * web service通信 * @param context * @param handler * @param methodName * 方法名 * @param flag * true:get data that should be resolved ;false:send data * @param cla * The class to be reflected * @param entityname * 需要轉換成類的包名string */ @SuppressWarnings(rawtypes) public Webservice(Context context, Handler handler, String methodName, boolean flag, Class cla, ParseData parse, String entityname) { URL = http:// + context.getSharedPreferences(ServiceIP, Context.MODE_PRIVATE).getString(IP, 127.0.0.1/EOIISService.asmx); tongXun(context, handler, methodName, flag, cla, parse, entityname); } /** * 以webservice獲取數據 */ @SuppressWarnings(rawtypes) private void tongXun(final Context context, final Handler handler, final String methodName, final boolean flag, final Class cla, final ParseData parse, final String entityname) { Thread thread = new Thread() { public void run() { webServiceThread(context, handler, methodName, flag, cla, parse, entityname); } }; thread.start(); // thread. } /** * 設置webservice要傳遞的屬性 */ public abstract void addProgerty(SoapObject rpc); /** * webservice 線程 * * @param context * @param handler * @param methodName * @param flag * true:get data that should be resolved ;false:send data * @param cla * The class to be reflected * @param entityname 需要轉換成類的包名string */ @SuppressWarnings(rawtypes) public void webServiceThread(final Context context, final Handler handler, String methodName, boolean flag, Class cla, final ParseData parse, String entityname) { try { // System.out.println(rpc------); // 指定webservice的命名空間和調用的方法名 Object obj1 = null; SoapObject rpc = new SoapObject(NAMESPACE, methodName); addProgerty(rpc); MyHttptran ht = new MyHttptran(URL, 5000); ht.debug = true; // 生成調用Webservice方法的SOAP請求信息.該信息由SoapSerializationEnvelope對象描述 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.bodyOut = rpc; envelope.dotNet = true; envelope.setOutputSoapObject(rpc); ht.call(NAMESPACE + methodName, envelope); if (envelope.bodyIn.toString().startsWith(SoapFault)) { SoapFault sf = (SoapFault) (envelope.bodyIn); Log.i(fault, sf.faultstring); if (handler != null) { Message message = Message.obtain(handler); message.what = 3; message.obj = sf.faultstring; message.sendToTarget(); } return; } // 得到返回結果 Log.i(bodyIn, envelope.bodyIn.toString()); SoapObject result = (SoapObject) envelope.bodyIn; if (result.toString().equals(methodName + Response{})) { // pd = false; if (null != handler) { // send message to the main thread Message message = Message.obtain(handler); // message.obj = year; message.what = 1; message.sendToTarget(); } return; } if (parse == null) { if (null != handler) { Message message = Message.obtain(handler); message.obj = result.getProperty(methodName + Result) .toString(); message.what = 1; message.sendToTarget(); } return; } SoapObject detail = (SoapObject) result.getProperty(methodName + Result); if (detail.toString().equals(anyType{})) { if (null != handler) { Message message = Message.obtain(handler); message.what = 2; message.sendToTarget(); } } else { obj1 = parse.doing(detail, cla, entityname); // 發送消息回主線程 if (null != handler) { Message message = Message.obtain(handler); message.obj = obj1; message.what = 0; message.sendToTarget(); } } } catch (ConnectException e) { e.printStackTrace(); if (null != handler) { handler.sendEmptyMessage(-1); } } catch (SocketTimeoutException e) { // TODO: handle exception e.printStackTrace(); if (null != handler) { handler.sendEmptyMessage(-1); } } catch (XmlPullParserException e) { // TODO: handle exception e.printStackTrace(); if (null != handler) { handler.sendEmptyMessage(-1); } } catch (Exception e) { e.printStackTrace(); if (null != handler) { Message message = Message.obtain(handler); message.obj = e.getMessage(); message.what = -2; message.sendToTarget(); } } } }關於將List
/** * 用於制造xml類型的字符串 * @author Administrator syc * @since 2012-10-31 */ public class CreateXml { public String createXml(@SuppressWarnings(rawtypes) List list, String tableName) { String xml = ; StringWriter xmlWriter = new StringWriter(); XmlSerializer xmlSerializer = Xml.newSerializer(); try { xmlSerializer.setOutput(xmlWriter); xmlSerializer.startDocument(UTF-16, null); xmlSerializer.startTag(, NewDataSet); // DT if (null != list) { FanShe reflect = new FanShe(); List轉化為XML調用方式如下:shuxingList = reflect.getPropertyNames(list.get(0) .getClass()); for (Object object : list) { xmlSerializer.startTag(, object.getClass().getName()); @SuppressWarnings(unchecked) List vlaueList = reflect.getValueList(shuxingList, object); for (int i = 0; i < shuxingList.size(); i++) { xmlSerializer.startTag(, shuxingList.get(i)); if (vlaueList.get(i) == null) { xmlSerializer.text(); } else { xmlSerializer.text(vlaueList.get(i)); } xmlSerializer.endTag(, shuxingList.get(i)); } xmlSerializer.endTag(, object.getClass().getName()); } xmlSerializer.endTag(, NewDataSet); // 屬性集合 xmlSerializer.endDocument(); xmlSerializer.flush(); // xmlWriter.flush(); xml = xmlWriter.toString().split(\?>)[1]; } } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return xml; } }
qiXieZzjlEntitieString = new CreateXml().createXml(qiXieZzjlEntities,qiXieZzjlEntities); //qiXieZzjlEntities聲明如下:private ListqiXieZzjlEntities = new ArrayList (); //qiXieZzjlEntities字符串名字可以任意
這個CardStackViewpager的靈感來自Github上面的 FlippableStackView開源項目,而我想實現的效果方向上恰好與FlippableStac
好久沒有寫博客了,最近都在忙。有時候即使是有時間也會很懶,就會想玩一玩,放松放松!一直都沒有什麼時間更新我這個菜鳥的博客了。不過今天不一樣,我要給大家講講怎麼實現許多ap
1、概述 相信做Android開發的寫得最多的就是ListView,GridView的適配器吧,記得以前開發一同事開發項目,一個項目下來基本就一直在寫Lis
先看效果圖: 首先,你得寫一個類我們命名為CornerListView[java]復制代碼 代碼如下:/** * 圓角ListView示例 * @De