我得到了以下onClick命令的按鈕。但是,當我把它稱爲沒有出現 CODE:加載HorizontalScrollView中的圖像和複選框
public void onClick(View v) {
Log.d("debug", "before loadGutschein");
loadGutschein();
ViewFlipperVino.setDisplayedChild(3);
layout_number = 3;
Log.d("debug", "after loadGutschein");
bottomAudioLogosLayout.postDelayed(new Runnable() {
DisplayMetrics metrics = getActivity().getResources().getDisplayMetrics();
int width = metrics.widthPixels;
@Override
public void run() {
Log.d("debug", "couponsout=" + coupons);
if (coupons != null) {
int coupSize = coupons.size();
final int itemWidth = (width/coupSize) - 5;
for (int i = 0; i < coupSize; i++) {
Coupon coupon = coupons.get(i);
if (coupon.getImage() != null) {
final CheckBox cb = new CheckBox(getActivity());
final ImageView iv = new ImageView(getActivity());
iv.setScaleType(ScaleType.CENTER_INSIDE);
LayoutParams linearLayoutParams = new LayoutParams();
iv.setLayoutParams(linearLayoutParams);
cb.setLayoutParams(linearLayoutParams);
bottomAudioLogosLayout.addView(iv);
bottomAudioLogosLayout.addView(cb);
ImageUtil.loadImage(coupon.getImage(), iv, -1, -1, "", false);
}
}
}
}
}, 200);
}
============ LoadGutschein方法:
private void loadGutschein() {
ServiceProxy.createWebServiceTask(getActivity(), new RemoteCallListener() {
@Override
public void onRemoteCallError(String response) {
Log.e("error", "onRemoteCallError is ==>" + response);
}
@Override
public void onRemoteCallComplete(Object response) {
Log.d("debug", "response is = " + response + "\t" + response.getClass());
coupons = (Coupons) response;
Log.d("debug", "coupons = " + coupons);
}
@Override
public void onNoInternetError() {
Log.e("error", "onNoInternetError");
}
@Override
public void onNoAccess() {
Log.e("error", "onNoAccess");
}
}, true, true).invokeGetCoupons();
}
=========我的logcat日誌:
08-13 14:36:11.382: D/debug(17576): gutscheinName= e
08-13 14:36:11.382: D/debug(17576): gutscheinHN= d
08-13 14:36:11.382: D/debug(17576): gutscheinCash= 50
08-13 14:36:11.382: D/debug(17576): before loadGutschein
08-13 14:36:11.445: D/debug(17576): after loadGutschein
08-13 14:36:11.515: I/WEB-SERVER-CLIENT GET :(17576): http://developer.weinco.de/api/v1/getCoupons?
08-13 14:36:11.648: D/debug(17576): couponsout=null
08-13 14:36:11.742: D/debug(17576): response is = [Coupon [Name=Rabatt, Code=321, GueltigBis=2014-09-01, Typ=absolut, Wert=10, GueltigAb=2011-09-01, Gueltig=alle]] class com.weinco.webservice.entity.Coupons
08-13 14:36:11.742: D/debug(17576): coupons = [Coupon [Name=Rabatt, Code=321, GueltigBis=2014-09-01, Typ=absolut, Wert=10, GueltigAb=2011-09-01, Gueltig=alle]]
我不知道爲什麼在postDelayed券值(couponsout在logcat中)爲空,如果從web服務的優惠券是在得到響應的valures。任何ideea我怎麼能解決這個問題?
優惠券是空的了其運行時。我想通過把延遲時間設爲400來解決這個問題。但是這並不能解決任何問題,因爲它取決於你的網絡連接和速度。 要解決它,我把「loadGutschein」叫成去在當前按鈕菜單中onClickListener。所以,直到我點擊並選擇我想要的菜單,它會在後臺加載優惠券。然後當我在其中一個按鈕上使用它(不僅使用loadGutschein的1)它已經加載。作爲LayoutParam的,不要緊,因爲畫面 – 2012-08-13 14:24:15
@rosualin延遲可能現在的工作,但你可能會面臨同樣的異常,如果某些用戶有一個真正的壞數據連接就變得一樣大。 – Luksprog 2012-08-13 14:27:58
他們必須選擇一個按鈕來加載一個佈局,然後將他們的數據放入一些edittexts中,然後纔會延遲調用post。所以它有很多時間來加載。我認爲它會超時,因爲服務器會在它崩潰之前 – 2012-08-13 14:30:31