凌空不能阻止JSON
问题描述:
添加日期列表视图我想应用显示在列表视图日期。我的应用程序有TabLayout
模仿this和Listviews
其模仿this。所以,标签有列表视图。在列表视图中显示所有json日期后,他们再次加载json日期。
当我刷卡每个标签像tab1→tab2→tab3→tab1→tab3...
它发生。
这是可能的代码。如果有人知道什么是错的,请教我。
凌空不能阻止JSON
public class AppController extends Application {
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized AppController getInstance() {
return mInstance;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public ImageLoader getImageLoader() {
getRequestQueue();
if (mImageLoader == null) {
mImageLoader = new ImageLoader(this.mRequestQueue,
new LruBitmapCache());
}
return this.mImageLoader;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
// set the default tag if tag is empty
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}
选项卡1(TAB2 TAB3和几乎相同)
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
adapter = new CSadapter(getActivity(),movieList);
setListAdapter(adapter);
getListView().setScrollingCacheEnabled(false);
pDialog = new ProgressDialog(getActivity());
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
// Creating volley request obj
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Song movie = new Song();
movie.setTitle(obj.getString("title"));
movie.setThumbnailUrl(obj.getString("jacket"));
movie.setNumber(obj.getString("number"));
movie.setYear(obj.getString("release"));
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
// notifying list adapter about data changes
// so that it renders the list view with updated data
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hidePDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(movieReq);
}
答
在寻呼机的默认页面限制为1。如果你超越你的网页活动创建一次。可能会发生here.You可以提高页面的限制,以避免重新创建
在寻呼机的默认页面限制为1。如果你超越所创建的页面活动一次。可能是这里发生的情况的情况。你可以增加pa GE的限制,以避免重新创建 – 2014-08-31 06:53:13
谢谢指教!我加了'setOffscreenPageLimit()'。我的应用程序不再重新载入json日期!
但我添加标签和'setOffscreenPageLimit(4)'因为应用程序有5tabs,它需要采取时间来证明第一个屏幕... – sakura 2014-08-31 07:53:32