private List<Map<String, String>> mlist;
private FinalBitmap fb;
初始化,准备请求服务器
public void initttq() {
mlist = new ArrayList<Map<String, String>>();
StringBuffer urlSb = new StringBuffer();
urlSb.append(getResources().getString(R.string.str_bcpservice_ip))
.append(":")
.append(getResources().getString(R.string.str_bcpservice_port))
.append("/mobileInterface/forum/note/home");
executeRequest(new JsonObjectRequest(Method.POST, urlSb.toString(),
getttqinfo(), ttqHomeResponseListener(), errorListener()));
}
提交请求数据
public JSONObject getttqinfo() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("smallCommunityCode", smallcommunitycode);
jsonObject.put("mobile", regeditmobile);
jsonObject.put("token", token);
jsonObject.put("recordNum", "3");
return jsonObject;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
监听服务器响应
private Response.Listener<JSONObject> ttqHomeResponseListener() {
return new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonobject) {
try {
System.out.println(jsonobject.toString());
JSONArray jsonarr = jsonobject.getJSONArray("list");
for (int i = 0; i < jsonarr.length(); i++) {
JSONObject jsonObj = jsonarr.getJSONObject(i);
final Map<String, String> map = new HashMap<String, String>();
Iterator it = jsonObj.keys();
while (it.hasNext()) {
String key = it.next();
String value = jsonObj.getString(key);
map.put(key, value);
}
mlist.add(map);
fb = FinalBitmap.create(getActivity());
fb.configLoadingImage(R.drawable.ic_launcher);
fb.configBitmapLoadThreadSize(5);
final ViewFlipper viewFlipper = (ViewFlipper) view
.findViewById(R.id.viewflipper);
try {
for (int j = 0; j < jsonObj.length(); j++) {
ImageView img = new ImageView(getActivity());
fb.display(img, mlist.get(j).get("titlePicPath").toString());
viewFlipper.addView(img);
initadvertising(viewFlipper);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
initTtqViewFlliper();
} catch (Exception ex) {
ex.printStackTrace();
}
}
};
}
执行自动播放
private void initadvertising(final ViewFlipper viewFlipper) {
viewFlipper.setAutoStart(true); // 设置自动播放功能(点击事件,前自动播放)
viewFlipper.setFlipInterval(2000);
if (viewFlipper.isAutoStart() && !viewFlipper.isFlipping()) {
viewFlipper.startFlipping();
Animation lInAnim = AnimationUtils.loadAnimation(getActivity(),
R.anim.push_left_in); // 向左滑动左侧进入的渐变效果(alpha 0.1 -> 1.0)
Animation lOutAnim = AnimationUtils.loadAnimation(getActivity(),
R.anim.push_left_out); // 向左滑动右侧滑出的渐变效果(alpha 1.0 -> 0.1)
viewFlipper.setInAnimation(lInAnim);
viewFlipper.setOutAnimation(lOutAnim);
viewFlipper.setDisplayedChild(3);
viewFlipper.showNext();
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。