解决RecylerView列表的意外外观

时间:2019-04-26 13:49:19

标签: java android-recyclerview

在为RecyclerView列表(如适配器)编写了必要的代码之后,我终于使该列表出现在列表Fragment中。唯一的问题是列表的最后一行是多余的,我正在尝试查找应该更改的代码/可能出现的问题。

我尝试修改代码的不同部分,例如适配器,模型类,在其中创建适配器实例并将其附加到RecyclerView的代码。我当然寻找类似问题的解决方案。恰好,我的问题是我应该在代码中哪里寻找问题。

这是连接列表,RecyclerView和适配器的代码:

context = getActivity();

Bundle listBundle = getArguments();
if (listBundle != null) {
    ArrayList<Movie> moviesList =getArguments().getParcelableArrayList("moviesList");
    String titleFromIntent = listBundle.getString("title");
    String releaseYearFromIntent = listBundle.getString("releaseYear");

    Movie moviesListEntryData = new Movie();
    moviesListEntryData.setTitle(titleFromIntent);
    moviesListEntryData.setTitle(releaseYearFromIntent);
    if (moviesList != null) {
        moviesList.add(moviesListEntryData);

        moviesAdapter = new MoviesAdapter(context);

        moviesRV = rootView.findViewById(R.id.moviesRVId);
        moviesRV.setLayoutManager(new LinearLayoutManager(context));

        //moviesRV.setItemAnimator(new DefaultItemAnimator());

        moviesRV.setHasFixedSize(true);
        moviesRV.setAdapter(moviesAdapter);

        moviesAdapter.attachMoviesList(moviesList);
    }
}

1 个答案:

答案 0 :(得分:0)

删除以下几行后,问题已解决:

    String releaseYearFromIntent = listBundle.getString("releaseYear");

    Movie moviesListEntryData = new Movie();
    moviesListEntryData.setTitle(titleFromIntent);
    moviesListEntryData.setTitle(releaseYearFromIntent);

moviesList.add(moviesListEntryData);