Skip to content

Commit 10eb109

Browse files
committed
修复博文界面点击头部返回顶部崩溃问题
1 parent 9ba50c2 commit 10eb109

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

app/src/main/java/com/rae/cnblogs/activity/BlogContentActivity.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.support.v4.app.FragmentTransaction;
77
import android.support.v7.widget.Toolbar;
88
import android.text.TextUtils;
9-
import android.util.Log;
109
import android.view.View;
1110
import android.widget.ImageView;
1211
import android.widget.TextView;
@@ -68,6 +67,8 @@ public class BlogContentActivity extends SwipeBackBaseActivity {
6867
private BlogShareDialog mShareDialog;
6968
private BlogBean mBlog;
7069
private BlogType mBlogType;
70+
private BlogCommentFragment mBlogCommentFragment;
71+
private BlogContentFragment mBlogContentFragment;
7172

7273
@Override
7374
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -118,12 +119,16 @@ protected void onViewSourceClick() {
118119
RaeImageLoader.displayHeaderImage(mBlog.getAvatar(), mAvatarView);
119120
mAuthorView.setText(mBlog.getAuthor());
120121
}
122+
// 评论
123+
mBlogCommentFragment = BlogCommentFragment.newInstance(mBlog, mBlogType);
124+
// 内容
125+
mBlogContentFragment = BlogContentFragment.newInstance(mBlog, mBlogType);
121126

122127

123128
// 加载Fragment
124129
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
125-
transaction.add(R.id.fl_comment, BlogCommentFragment.newInstance(mBlog, mBlogType));
126-
transaction.add(R.id.fl_content, BlogContentFragment.newInstance(mBlog, mBlogType));
130+
transaction.add(R.id.fl_comment, mBlogCommentFragment);
131+
transaction.add(R.id.fl_content, mBlogContentFragment);
127132
transaction.commit();
128133

129134
}
@@ -166,13 +171,10 @@ public void onActionBarClick() {
166171
}
167172

168173
if (mCommentLayout.getVisibility() == View.VISIBLE) {
169-
BlogCommentFragment fragment = (BlogCommentFragment) fragments.get(0);
170-
fragment.scrollToTop();
174+
mBlogCommentFragment.scrollToTop();
171175
} else {
172-
BlogContentFragment fragment = (BlogContentFragment) fragments.get(1);
173-
fragment.scrollToTop();
176+
mBlogContentFragment.scrollToTop();
174177
}
175-
176178
}
177179

178180

0 commit comments

Comments
 (0)