簡體   English   中英

強制改造以加載新數據

[英]Force retrofit to load new data

我正在使用改造在我的回收視圖中獲取我的 json 數據。 幾周前它曾經可以正常工作,但我現在運行代碼,然后它只加載一次數據,然后在我更改任何文本或在 json 數據中添加新值時多次加載,它總是在加載時加載相同的初始數據。 我沒有使用任何緩存屬性,奇怪的是一旦它第一次加載,那么如果我刪除我的 json 然后它仍然加載數據而不是拋出異常並給出未找到的 json 錯誤。

我錯過了什么。 我更改了改造版本,但似乎不起作用。 這是我的 Mainactivity 代碼是

 GetDataService service = RetrofitClientInstance.getRetrofitInstance().create(GetDataService.class); Call<List<RetroPhoto>> call = service.getAllPhotos(); call.enqueue(new Callback<List<RetroPhoto>>() { @Override public void onResponse(Call<List<RetroPhoto>> call, Response<List<RetroPhoto>> response) { progressDoalog.dismiss(); generateDataList(response.body()); } @Override public void onFailure(Call<List<RetroPhoto>> call, Throwable t) { progressDoalog.dismiss(); Toast.makeText(NewsActivity.this, "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show(); } }); } /*Method to generate List of data using RecyclerView with custom adapter*/ private void generateDataList(List<RetroPhoto> photoList) { recyclerView = findViewById(R.id.customRecyclerView); adapter = new CustomAdapter(this,photoList); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(NewsActivity.this); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); }

GetDataService 的代碼是

 public interface GetDataService { @GET("b.json") Call<List<RetroPhoto>> getAllPhotos(); }

我的畢業證是

 implementation 'com.squareup.retrofit2:retrofit:2.3.0' implementation 'com.squareup.retrofit2:converter-gson:2.3.0' implementation 'com.squareup.okhttp:okhttp:2.4.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.7.0' compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'

在此先感謝您的幫助。 為了弄清楚在幾周內我什至沒有接觸代碼的情況下究竟發生了什么,我在地板上敲了 3 個多小時。

我意識到問題出在服務器端,因為我正在使用 ipage 軟管,我將 json 移動到其他軟管,並立即根據請求在應用程序中顯示更改,但 ipage 沒有。 所以代碼沒問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM