这是我的问题,滚动评论时显示无限视图 当布局滚动时,它会显示无穷大的视图(注释),而不会连续结束。我只想显示用户的确切注释(而不是无穷大) 任何人请帮助我摆脱它 提前致谢 这是我的Java代码
public class CommentsActivity extends AppCompatActivity implements View.OnClickListener {
private RecyclerView mList;
private PaginationAdapter mAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mList = findViewById(R.id.list);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext(),
LinearLayoutManager.VERTICAL, false);
mList.setLayoutManager(mLayoutManager);
mList.setItemAnimator(new DefaultItemAnimator());
}
@Override
protected void onStart() {
super.onStart();
String storyKey = getIntent().getStringExtra(EXTRA_STORY_KEY);
if (storyKey != null) {
// load comments
showComments(storyKey);
}
}
@Override
protected void onStop() {
super.onStop();
if (mAdapter != null) {
mAdapter.cleanup();
}
}
private void showComments(String storyKey) {
if (mAdapter == null) {
Analytics.trackOpenComments(storyKey);
DatabaseReference ref = Comment.collection(storyKey);
mAdapter = new PaginationAdapter<CommentViewHolder>(CommentViewHolder.class, R.layout.comment_item, ref) {
@Override
protected void populateViewHolder(CommentViewHolder viewHolder, DataSnapshot snapshot, int position) {
viewHolder.bind(snapshot.getValue(Comment.class), snapshot.getRef());
}
};
mList.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
} else {
mAdapter.notifyDataSetChanged();
}
}
private void showComments(String storyKey) {
if (mAdapter == null) {
Analytics.trackOpenComments(storyKey);
DatabaseReference ref = Comment.collection(storyKey);
mAdapter = new PaginationAdapter<CommentViewHolder>(CommentViewHolder.class, R.layout.comment_item, ref) {
@Override
protected void populateViewHolder(CommentViewHolder viewHolder, DataSnapshot snapshot, int position) {
viewHolder.bind(snapshot.getValue(Comment.class), snapshot.getRef());
}
};
mList.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
} else {
mAdapter.notifyDataSetChanged();
}
}
private void showComments(String storyKey) {
if (mAdapter == null) {
Analytics.trackOpenComments(storyKey);
DatabaseReference ref = Comment.collection(storyKey);
mAdapter = new PaginationAdapter<CommentViewHolder>(CommentViewHolder.class, R.layout.comment_item, ref) {
@Override
protected void populateViewHolder(CommentViewHolder viewHolder, DataSnapshot snapshot, int position) {
viewHolder.bind(snapshot.getValue(Comment.class), snapshot.getRef());
}
};
mList.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
} else {
mAdapter.notifyDataSetChanged();
}
}
这是我用于回收者视图的xml代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="me.a01eg.canyon.mustage.CommentsActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:listitem="@layout/comment_item" />