【发布时间】:2016-10-04 10:39:46
【问题描述】:
希望您能在这方面提供帮助。
我有一个PostFragment,其中包含一个线程的所有帖子的RecyclerView。这个想法是让用户点击FAB,将他们带到NewPostActivity,允许他们回复。当我在NewPostActivity 中按“发布”时,如何更新PostFragment 中的适配器。
目前我在片段中尝试了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();
}
}
我尝试在此处阅读,但找不到任何适合此的内容。
提前致谢。
【问题讨论】:
-
发布的数据是否插入到
PostFragment中的同一个列表中? -
请分享您如何设置适配器和列表的代码。我没有看到列表更新为新数据。
onPostDataReceived没有更新任何列表
标签: android android-fragments android-activity android-recyclerview notifydatasetchanged