try {
JSONObject object = new JSONObject(jsonData);
String status = object.getString("status");
System.out.print(status);
String postsstr = object.getString("posts");
JSONArray ports = new JSONArray(postsstr);
for(int i = 0;i<ports.length();i++){
port = ports.getJSONObject(i);
id = port.getString("id");
title = port.getString("title");
custom_fields = port.getString("custom_fields");
// System.out.print(custom_fields);
picJson = new JSONObject(custom_fields);
if(picJson.has("slider_pic") == true){
slider_pic_URL=picJson.getString("slider_pic");
System.out.println("圖片鏈接"+slider_pic_URL);
picList = new JSONArray(slider_pic_URL);
for (int j =0; j<picList.length(); j++) {
slider_pic_URL = picList.getString(j);
System.out.println(slider_pic_URL);}
想把這裡的slider_pic_URL 傳遞到initviews()中
private void initViews() {
llAdvertiseBoard = (LinearLayout) this.findViewById(R.id.llAdvertiseBoard);
final JSONArray advertiseArray = new JSONArray();
class receiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO 自動生成的方法存根
String TPRUL =intent.getStringExtra("tpv");
System.out.println(TPRUL);
advertiseArray.put(TPRUL);
}
}
llAdvertiseBoard.addView(new Advertisements(this, true, inflater, 3000).initView(advertiseArray));
// try {
// JSONObject head_img0 = new JSONObject();
// head_img0.put("head_img","http://www.zjhaining.com/uploads/2015/10/byf1118.jpg");
//
//
// advertiseArray.put(head_img0);
//
//
// } catch (JSONException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
在initviews中創建了一個json數組 想把handler中解析出的鏈接傳遞給initviews中的
json數組中 從而可以加載出鏈接 急 求解答 我試了用intent 不行
用這個:存放用鍵值對形式:HealthMap.put("key", 要傳遞的值);,用的時候直接用HealthMap.get("key");就可以了
public class HealthMap {
private static Map map = new ConcurrentHashMap();
/**
* 傳值
* @param key
* @param obj
*/
public static void put(String key, Object obj) {
map.put(key, obj);
}
/**
* 取值 默認刪除內存引用
* @param key
* @return
*/
public static Object get(String key) {
return map.remove(key);
}
/**
* 取值 自定義是否刪除內存引用
* @param key
* @param isDelete
* @return
*/
public static Object get(String key, boolean isDelete) {
if (isDelete) {
return get(key);
} else {
return map.get(key);
}
}
}