我使用AQuery demo app中的以下代码,xml始终为null
如何重新获取与我在Google帐户列表中选择的帐户相关的信息?
public void auth_specific_account(){
String url = "https://www.google.com/reader/atom/user/-/state/com.google/reading-list?n=8";
AjaxCallback<XmlDom> cb = new AjaxCallback<XmlDom>();
cb.url(url).type(XmlDom.class).weakHandler(this, "readerCb");
cb.auth(this, AQuery.AUTH_READER, AQuery.ACTIVE_ACCOUNT);
aq.progress(R.id.progress).ajax(cb);
}
public void readerCb(String url, XmlDom xml, AjaxStatus status) {
if(xml != null){
List<XmlDom> entries = xml.tags("entry");
List<String> titles = new ArrayList<String>();
for(XmlDom entry: entries){
titles.add(entry.text("title"));
}
showTextResult(titles);
}
AQUtility.debug("status:" + status);
showResult(xml, status);
}
答案 0 :(得分:0)
当不需要弱处理程序时,可以使用不同的方法,通过传递给aq.ajax()扩展AjaxCallback的对象,该对象获取有关应该使用请求的项的信息。
private class AjaxCallbackAddingMarker extends AjaxCallback<Bitmap> {
private final Item item;
AjaxCallbackAddingMarker(Item item) {
this.item = item;
}
@Override
public synchronized void callback(String url, Bitmap object, AjaxStatus status) {
// do something with item and downloaded Bitmap
}
};
如果你想使用weakHandler,那么这就是我的解决方案:
private void loadImage(final ImageView image, String url) {
Bitmap bmp = aq.getCachedImage(url);
if (bmp!= null) {
image.setImageBitmap(bmp);
return;
}
Object handler = new Object() {
@SuppressWarnings("unused")
public void callback(String url, Bitmap bmp, AjaxStatus status) {
if (bmp != null) {
image.setImageBitmap(bmp);
}
}
};
AjaxCallback<Bitmap> bmpCallback = new AjaxCallback<Bitmap>();
bmpCallback.type(Bitmap.class).url(url).header("User-Agent", appPrefs.getUserAgent()).policy(AQuery.CACHE_PERSISTENT)
.expire(GlobalVars.MARKERS_CACHE_EXPIRE).fileCache(true).weakHandler(handler, "callback");
aq.ajax(bmpCallback);
}