Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RecyclerView未显示列表中的所有项目_Android_Android Recyclerview - Fatal编程技术网

Android RecyclerView未显示列表中的所有项目

Android RecyclerView未显示列表中的所有项目,android,android-recyclerview,Android,Android Recyclerview,我正在我的应用程序中使用RecyclerView。每次打开屏幕时,我只能看到一个项目,但每次调试时,它都会出现在BindViewHolder方法中 这是我的适配器: @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.la

我正在我的应用程序中使用
RecyclerView
。每次打开屏幕时,我只能看到一个项目,但每次调试时,它都会出现在BindViewHolder方法中

这是我的适配器:

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.tourist_details_info, parent, false);

    return new ViewHolder(itemView);
}

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
    try {
            holder.displayName.setText(list.get(position).toUpperCase());
    }catch (Exception e){
       AxeltaLogger.err("error>>>"+e);
    }
}
@Override
public int getItemCount() {
    return list.size();
}
这是我的回收视图:

 RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setHasFixedSize(true);
touristAdapter=new TouristInfoAdapter(list);
recyclerView.setAdapter(touristAdapter);

在您的布局中,将父级高度从匹配父级设置为特定高度(100dp或其他),或者使用
包装内容
作为
android:layout\u height=“match\u parent”

这是每个人在使用recyclerView时最常见的错误。而不是在onBindViewHolder中使用位置,您必须使用

holder.getAdapterPosition()
从列表中获取数据时。您在onBindViewHolder中使用的位置是项目在屏幕上的位置,该位置将限制为当前屏幕上的最大项目数

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
    try {
        holder.displayName.setText(list.get(holder.getAdapterPosition().toUpperCase());
    } 
    catch (Exception e) {
        AxeltaLogger.err("error>>>" + e);
    }
}

希望这有帮助。

如果您在
ScrollView
中使用
RecyclerView
,请将
ScrollView
替换为
NestedScrollView

在RecyclerView中启用android:nestedScrollingEnabled=“false”


这解决了我的问题。

我现在觉得自己很笨,但也许我可以帮助别人:

我的问题是,方向设置为水平,因为我从应用程序的其他位置复制和粘贴,将其更改为垂直,效果很好

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

我得到了相同的错误,原因与@acua描述的相同。我也使用了水平线性布局,所以一定要检查它。

问题出在ScrollingView上。当我们在其中使用RecyclerView时,这种情况经常发生


您只需使用android.core.widget.NestedScrollView更改ScrollingView即可。

请将您的自定义布局粘贴到此处我认为您的布局R.layout.Tourism\u详细信息\u信息高度已设置为匹配\u家长是以前的匹配\u家长现在工作正常感谢Maicon Hellmanni设置为匹配\u家长这并没有显示其他详细信息您必须更改适配器设置,如我在上述代码中所述。在更改High以包装内容后,如果项目数量超过其所能容纳的数量,则视图中将有重复的项目。检查这一点。没有解决我的问题,问题是我想显示图书信息,在一些图书中信息是完整的,而另一些图书中信息很少。。我不知道tbhWorks 100%有什么问题,我将我的
ScrollView
替换为
androidx.core.widget.NestedScrollView
,并将
android:nestedScrollingEnabled=“false”
添加到现在的
NestedScrollView
中的回收器视图中。它会按预期完全展开所有项目!感谢您的回答,但是在这个特定问题的上下文中,我不清楚询问者是否有滚动视图;所以在这种情况下,我认为你的答案与这个问题没有直接关系。