希望你能對此提供幫助。發佈評論時更新Recyclerview
我有一個PostFragment
其中包含RecyclerView
一個線程的所有職位。這個想法是讓用戶點擊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();
}
}
我試圖在這裏讀書了,但真的不能找到適合這樣的東西。
在此先感謝。
發佈的數據是否插入到PostFragment中的同一個列表中? –
是@ReazMurshed – BilalMH
請分享如何設置適配器和列表的代碼。我沒有看到列表更新了新的數據。 'onPostDataReceived'沒有更新任何列表 –