2016-11-22 90 views
1

我有一个处理recyclerview的问题,当我打开另一个活动后返回活动时,它会复制我显示的所有项目。有没有什么办法解决这一问题?RecyclerView重复每个项目

和列表视图一样,它只是自动清除列表,然后再次显示。你能告诉我怎么样?感谢

的OnCreate

int x = 0; 
       for(String Name : property_name){ 
        JSONObject jsonObject = arrayResponse.getJSONObject(x); 
        property_id[x] = jsonObject.getString("property_id"); 
        property_name[x] = jsonObject.getString("property_name"); 
        type[x] = jsonObject.getString("property_type"); 
        price[x] = jsonObject.getString("price"); 
        address[x] = jsonObject.getString("address"); 

        ListingNearby listingNearby = new ListingNearby(property_id[x], property_name[x], type[x], price[x], Math.round(distance[x])); 
        x++; 
        list.add(listingNearby); 

       } 

       recyclerView = (RecyclerView) findViewById(R.id.ln_recycler_view); 
       layoutManager = new LinearLayoutManager(this); 
       recyclerView.setLayoutManager(layoutManager); 
       recyclerView.setHasFixedSize(true); 
       adapter = new ListingNearbyAdapter(list); 
       recyclerView.setAdapter(adapter); 

我不知道要放什么的onResume使列表视图清除列表,然后再次显示它。

+0

看起来你已经搞乱了你的'onResume' ... –

+0

我应该把什么放在onResume? –

+0

当我不知道你的代码是什么样的时候,我可以怎样帮助你? –

回答

2

只需尝试list.clear(),然后再开始循环。我想你的列表是一种静态变量。