編輯:關於Android編程
/**
* 數據解析接口
*/
public interface ParseData {
/**
* @param result
* Soap數據對象
* @param cla
* Class類
* @param entityname
* 包名
* @return
*/
public abstract Object doing(SoapObject result,
@SuppressWarnings("rawtypes") Class cla, String entityname)
throws NoSuchFieldException, IllegalAccessException,
InstantiationException, ClassNotFoundException;
}二、返回數據為單個類的情況
/**
* 數據為單個類
* @author Administrator
*/
public class OneClass implements ParseData {
@Override
public Object doing(SoapObject result,
@SuppressWarnings("rawtypes") Class cla, String entityname)
throws NoSuchFieldException, IllegalAccessException,
InstantiationException, ClassNotFoundException {
// TODO Auto-generated method stub
FanShe fs = new FanShe();
Object obj = fs.useFanSheToData(result, cla.newInstance(), entityname);
return obj;
}
}三、數據為多個String的情況
/**
* 數據為多個String
* @author Administrator
*/
public class ManyString implements ParseData {
@Override
public Object doing(SoapObject result,
@SuppressWarnings("rawtypes") Class cla, String entityname)
throws NoSuchFieldException, IllegalAccessException,
InstantiationException, ClassNotFoundException {
// TODO Auto-generated method stub
String[] zsts = new String[result.getPropertyCount()];
for (int i = 0; i < result.getPropertyCount(); i++) {
zsts[i] = result.getProperty(i).toString();
}
return zsts;
}
}四、數據為List
/** * 數據為List五、數據為DataTable的情況下解析
/**
* 數據為DateTable類型解析
* @author Administrator syc
*/
public class DataTable implements ParseData {
@Override
public Object doing(SoapObject result,
@SuppressWarnings("rawtypes") Class cla, String entityname)
throws NoSuchFieldException, IllegalAccessException,
InstantiationException, ClassNotFoundException {
// TODO Auto-generated method stub
FanShe fs = new FanShe();
List list = new ArrayList();
if (result.toString().indexOf("diffgram") >= 0) {
//System.out.println(result.getProperty("diffgram").toString());
if (result.getProperty("diffgram").toString().equals("anyType{}")) {
return null;
}
SoapObject diffgram = (SoapObject) result.getProperty("diffgram");
SoapObject documentelement = (SoapObject) diffgram.getProperty(0);
for (int i = 0; i < documentelement.getPropertyCount(); i++) {
// System.out.println(i);
// System.out.println(documentelement.getPropertyCount());
SoapObject bedtable = (SoapObject) documentelement
.getProperty(i);
Object obj = fs.useFanSheToData(bedtable, cla.newInstance(),
entityname);
list.add(obj);
}
}
return list;
}
} 六、數據為DataSet的數據解析
/**
* 數據為DateSet類型解析
* @author Administrator
*/
public class DataSet implements ParseData {
@Override
public Object doing(SoapObject result,
@SuppressWarnings("rawtypes") Class cla, String entityname)
throws NoSuchFieldException, IllegalAccessException,
InstantiationException, ClassNotFoundException {
// TODO Auto-generated method stub
Object obj = null;
if (result.toString().indexOf("diffgram") >= 0) {
SoapObject diffgram = (SoapObject) result.getProperty("diffgram");
obj = obtainshuju(diffgram, cla, entityname);
}
return obj;
}
/**
* 有diffgram把傳回來的list數據解析在反射
* @param diffgram
* @param cla
*/
public Object obtainshuju(SoapObject diffgram,
@SuppressWarnings("rawtypes") Class cla, String entityname)
throws NoSuchFieldException, IllegalAccessException,
InstantiationException, ClassNotFoundException {
FanShe fs = new FanShe();
List clalist = new ArrayList();
SoapObject NewDataSet = (SoapObject) diffgram.getProperty("NewDataSet");
if (NewDataSet.getPropertyCount() == 1
&& ((SoapObject) NewDataSet.getProperty(0)).getPropertyCount() == 1) {
return ((SoapObject) NewDataSet.getProperty(0)).getProperty(0)
.toString();
}
// 取得一個個類的屬性賦值
for (int i = 0; i < NewDataSet.getPropertyCount(); i++) {
SoapObject table = (SoapObject) NewDataSet.getProperty(i);
System.out.println(table.toString());
Object obj = fs.useFanSheToData(table, cla.newInstance(),
entityname);
clalist.add(obj);
}
return clalist;
}
} 七、類中有類的數據解析
/**
* 類中有類
* @author Administrator syc
*/
public class Classinclass implements ParseData {
@Override
public Object doing(SoapObject result,
@SuppressWarnings("rawtypes") Class cla, String entityname)
throws NoSuchFieldException, IllegalAccessException,
InstantiationException, ClassNotFoundException {
FanShe fs = new FanShe();
List list = new ArrayList();
for (int i = 0; i < result.getPropertyCount(); i++) {
SoapObject result1 = (SoapObject) result.getProperty(i);
// System.out.println(result.toString());
Object obj = fs.useFanSheToData(result1, cla.newInstance(),
entityname);
list.add(obj);
}
return list;
}
}
10min了解ContentProvider
我們學的Android 數據持久化的技術包括文件存儲、SharedPreferences 存儲、以及數據庫存儲。不知道你有沒有發現,使用這些持久化技術所保存的數據都只能在
Android 自定義控件之可多選課程日歷CalendarView
效果圖開發環境IDE版本:AndroidStudio2.0物理機版本:Win7旗艦版(64位)前言最近的項目中用到了一個課程選擇的日歷View,於是在網上搜了搜自定義日歷
Android---項目分享(附源碼)
大概2年前寫的一個小項目,那時候貌似是春節。在家比較閒,花了近一個月(本想寫著拿去參加比賽的,文檔都寫好了。後來想想算了,拿另一個去了,這個就當練手了)。一個人做的,又寫
Android 實現微信,微博,微信朋友圈,QQ分享的功能
Android 實現微信,微博,微信朋友圈,QQ分享的功能一、去各自所在的開發者平台注冊相應的Key值;引入相關jar包、權限等二、ShareUtil工具類import