2016-09-17 4 views
-1

페이지 매김을 구현하는 동안 데이터를 지워야합니다. 아래 코드를 사용하여 JSON 응답을 deserialize하고 어댑터에서 피드를 사용했습니다. 데이터가 내 이전 데이터를 교체의 내가 더 스크롤 추가하면서, 데이터의 첫 번째 세트에 대한 제대로 작동recyclerview + GSON을 사용하여 페이지 매김을 구현하는 동안 데이터를 지우는 방법

Gson gson = new Gson(); 
     List<MyDataModel> mcontentList = Arrays.asList(gson.fromJson(getResponse, MyDataModel.class)); 
     mAdapter = new MyDataAdapter(getApplicationContext(), mcontentList.get(0).getResponse().getCoreContent()); 
     mRecyclerView.setAdapter(mAdapter); 
     mRecyclerView.getAdapter().notifyDataSetChanged(); 

모든 것은 /이 문제를 처리하기 위해 나에게 조언을, 다음 세트를 매김.

감사합니다. 당신은 오래된 데이터를 삭제 할 때마다 때문에 빈리스트와 MyDataAdapter 하나의 방법을 만들 공공 및 설정 어댑터에서

답변

1

를 호출하기 전에 때문이다. 어댑터에서

는 잘 작동이 방법

void addData(List<MyDataModel> newData){ 
    for(MyDataModel data:newData) 
    listData.add(data); 
} 

다음

if(mAdapter==null){ 
    mAdapter = new MyDataAdapter(getApplicationContext(), mcontentList.get(0).getResponse().getCoreContent()); 
      mRecyclerView.setAdapter(mAdapter); 
} 
else{ 
mAdapter.addData(mcontentList); 
} 
+0

감사를 추가 – Aerrow

0

이 방법

void addData(List<Your Object> mcontentList){ 
       yourList.addAll(mcontentList); 
       notifyDataSetChanged(); 
              } 
관련 문제