class data
{
...
//取得数据
public Data getData(key) {
Data data = new Data();
params.put("word", key);
// 调用API取得数据
new DataLoader(){
@Override
public void resultSFSearchDataJSONParser(
SFSearchCountJSONParser sfSearchCountJSONParser, boolean isSuccess) {
// TODO Auto-generated method stub
super.resultSFSearchDataJSONParser(sfSearchCountJSONParser,isSuccess);
data = (Data)sfSearchCountJSONParser.result.get(0);
}
}.getData(this.key);
return data;
}
}
// API取得数据
class DataLoader implements SFSearchJSONParserDelegate {
Data data = new Data();
private SFSearchCountJSONParser searchJSONParser = null;
private HashMap<String, String> params = new HashMap<String, String>();
public void getData(String key) {
params.put("word", key);
searchJSONParser = new SFSearchCountJSONParser();
searchJSONParser.parserDelegate = this;
searchJSONParser.executeStockSearchCountByParams(params);
}
// 结果返回函数
@Override
public void resultSFSearchDataJSONParser(
SFSearchCountJSONParser sfSearchCountJSONParser, boolean isSuccess) {
// TODO Auto-generated method stub
data = (Data)sfSearchCountJSONParser.result.get(0);
}