Android RecyclerView滚动时重复项目
答
RecyclerView
将回收视图。删除数据时,请拨打notifyItemChanged(pos)
或notifyDataSetChanged()
方法。
+0
Sepasgozaram,(谢谢你,为我工作) – RayaCoder
答
这是你的notifyDataSetChanged()
这是问题。
检查您是否正确使用它。
即:
private void parseJsonFeed(JSONArray response) {
for (int i = 0; i < response.length(); i++)
try {
JSONObject obj = response.getJSONObject(i);
MyData myData = new MyData();
myData.setContent_title(obj.getString("content_title"));
...
...
...
...
// adding content to array
homeList.add(myData);
} catch (JSONException e) {
e.printStackTrace();
}
//Notifying the adapter that data has been added or changed
//this must always be called else the recycler would not understand when to stop or start working.
recyclerViewAdapter.notifyDataSetChanged();
}
答
我知道它的晚,但希望这将帮助别人。在您的适配器中覆盖这两种方法。
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
return position;
}
添加代码,请 –
看到这里http://*.com/a/36327143/3145960 –
@mehrdadkhosravi答案补充现在的代码。 – RayaCoder