2014-08-31 76 views
1

添加日期列表視圖我想應用顯示在列表視圖日期。我的應用程序有TabLayout模仿thisListviews其模仿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); 
} 
+0

在尋呼機的默認頁面限制爲1。如果你超越所創建的頁面活動一次。可能是這裏發生的情況的情況。你可以增加pa GE的限制,以避免重新創建 – 2014-08-31 06:53:13

+0

謝謝指教!我加了'setOffscreenPageLimit()'。我的應用程序不再重新載入json日期!
但我添加標籤和'setOffscreenPageLimit(4)'因爲應用程序有5tabs,它需要採取時間來證明第一個屏幕... – sakura 2014-08-31 07:53:32

回答

0

在尋呼機的默認頁面限制爲1。如果你超越你的網頁活動創建一次。可能會發生here.You可以提高頁面的限制,以避免重新創建