Jarvis Millan Jarvis Millan - 3 months ago 21
Android Question

RecyclerView duplicates every item

I have a problem dealing with recyclerview, when i return back to the activity after opening another activity, it duplicates all the items i displayed. Is there any way to fix this?

Like on list view, it just automatically clears the list and then display it again. can you show me how? thanks


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]));


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

I wonder what to put in onResume so that the listview clears the list and then display it again.


Just try to list.clear() before you begin your loop. I guess your list is kind of static variable.