2017-07-15 10 views
0

にnotifyDataSetChanged呼び出しが、私はアダプタを作成し、空のリストを持つクラスを通過した後、リフレッシュしません要素は、アダプタ

public void setItems(Posts newPosts) { 
    Log.i("mytag", "NewPosts items number in the setItems method: " + Integer.toString(newPosts.items.size())); 
    posts.items.addAll(newPosts.items); 
    Log.i("mytag", "Posts items number in the setItems method: " + Integer.toString(posts.items.size())); 
    posts.profiles.addAll(newPosts.profiles); 
    posts.groups.addAll(newPosts.groups); 
    notifyDataSetChanged(); 
} 

そして、これはgetItemCountがどのように見えるかです:ログで

@Override 
public int getItemCount() { 
    Log.i("mytag", "Posts items number in the getitemcount method: " + Integer.toString(posts.items.size())); 
    return posts.items.size(); 
} 

07-15 18:57:41.967 7481-7481/com.ovchinnikovm.android.vktop I/mytag: Posts items number in the getitemcount method: 0 
07-15 18:57:41.967 7481-7481/com.ovchinnikovm.android.vktop I/mytag: Posts items number in the getitemcount method: 0 
07-15 18:57:42.005 7481-7481/com.ovchinnikovm.android.vktop I/mytag: Posts items number in the getitemcount method: 0 
07-15 18:57:42.005 7481-7481/com.ovchinnikovm.android.vktop I/mytag: Posts items number in the getitemcount method: 0 
07-15 18:57:42.118 7481-7481/com.ovchinnikovm.android.vktop I/mytag: NewPosts items number in the setItems method: 20 
07-15 18:57:42.118 7481-7481/com.ovchinnikovm.android.vktop I/mytag: Posts items number in the setItems method: 20 

私はrecyclerviewを正しく更新するにはどうすればよいですか?あなたのアダプタを再初期化してみaddAll()

+0

インスタンス化時にアイテムのリストをアダプタに渡していないか、間違ったリストを更新しているようですが、アダプタのコンストラクタのスニペットをポストしてインスタンス化することができますか? –

+0

@NoelOmondi pastebin.com/fYyHfv4E - アダプターpastebin.com/Q5zskEmm - アクティビティーpastebin.com/ZAsrjHeg - ダガーの​​モジュール –

+0

これらのファイルを通過しました。空のPOSTアイテムをアダプターに渡しているようですあなたのPostsActivityのsetPosts()メソッドに実際にその中の投稿が含まれている場合 –

答えて

-1

してみてください。

+0

まだ、同じ問題がある –

-1

を呼び出す前に、あなたのListの上clear()メソッドを呼び出すための

+0

これは質問への答えを提供しません。十分な[評判](https://stackoverflow.com/help/whats-reputation)があれば、[投稿にコメントする]ことができます(https://stackoverflow.com/help/privileges/comment)。代わりに、[質問者からの明確化を必要としない回答を提供する](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- i-do-代わりに)。 - [レビューから](/レビュー/低品質の投稿/ 16724009) – www