2017-04-26 40 views
-1

每當api服務器只返回一個json數據時,我的回收視圖始終是錯誤的。我正在使用zomato做食物推薦系統,每次搜索查詢只返回一家餐廳時,它不會顯示它。就在它只有一家餐館的時候。當它不止一個時它工作得很好。RecyclerView每次錯誤Json結果只有一個項目

我的代碼:

First part of my code

Second part of my code

對不起,我不知道如何寫在後的代碼,所以我將它張貼在一個屏幕截圖的形式...

哦,zomato api(/ search)的json格式可以在https://開發者頁面看到。 zomato。 COM /文檔LANG =編號/餐廳/搜索

+1

粘貼代碼在你的文章中,突出顯示它,然後點擊{}按鈕。這會將其格式化爲代碼。 – coinbird

回答

0

你用?!

filterAdapter.notifyItemRangeInserted(curSize, filterRestaurantData.size() - 1) 

將通過(1,0)時,只有一個項目是在列表中。

但這種方法需要的參數(啓動,計數)

所以你添加像以前一樣,你應該得到的尺寸:

int oldSize = filterRestaurantData.size(); 
filterRestaurantData.addAll(searchResult...) 

和以後使用:

int numAdded = filterRestaurantData.size() - oldSize; 
filterAdapter.notifyItemRangeInserted(oldSize, numAdded); 
相關問題