コメントを投稿すると、Recyclerviewが更新されます
私は、スレッドのすべての投稿のRecyclerView
を含むPostFragment
を持っています。考え方はユーザーがFABをクリックして、NewPostActivity
に返信することです。返信することができます。 PostFragment
のアダプタを更新するにはどうすればいいですか?NewPostActivity
の「投稿」を押してください。
現時点では、フラグメントにonResume
を試しましたが、動作しません。私の「ポスト」ボタンをクリックしたときのコードです。
private void addPost() {
String newPost = replaceHTMLTags(mPostMessage.getHtml());
String threadID = PreferenceConnector.readString(getApplicationContext(),
"threadID");
String username = PreferenceConnector.readString(getApplicationContext(),
"username");
mDataFactory = new PostFeedDataFactory(this);
mDataFactory.createNewPost(threadID, newPost, username,
new PostFeedDataFactory.PostFeedDataFactoryCallback() {
@Override
public void onPostDataReceived(PostResponse response) {
Toast.makeText(getApplicationContext(), "Posted successfully",
Toast.LENGTH_LONG).show();
finish();
}
@Override
public void onPostDataFailed(Exception exception) {
Toast.makeText(getApplicationContext(), exception.getMessage(),
Toast.LENGTH_LONG).show();
finish();
}
});
}
そして、私のonResume
は、基本的にはちょうど
@Override
public void onResume() {
super.onResume();
if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
}
}
である私はここにアップ読んでみましたが、本当にこれに適した何かを見つけることができません。
ありがとうございます。
if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
}
そしてfinish()
前PostFeedDataFactoryCallback()
の両方の方法でそれを呼び出す:
投稿されたデータは、 'PostFragment'にある同じリストに挿入されていますか? –
はい@ReazMurshed – BilalMH
アダプターとリストの設定方法をコードでお知らせください。リストに新しいデータが更新されているとは思われません。 'onPostDataReceived'はリストを更新していません –