androidx中的回收器视图有问题,未显示所有数据或不显示数据 不正确的字符串数组。适配器似乎正在工作,因为它试图显示阵列列表中的所有项目,但是在滚动浏览数据时,回收站将停止正常工作。在某一时刻,回收站仅更改框架之一以显示阵列中的所有项目。它还会重复数组中的一组项目(即1-10),而不是显示整个数组(即1-30)。我试图张贴一些图片以进一步说明。
<string-array name="example_array">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
<item>14</item>
<item>15</item>
<item>16</item>
<item>17</item>
<item>18</item>
<item>19</item>
<item>20</item>
<item>21</item>
<item>22</item>
<item>23</item>
<item>24</item>
<item>25</item>
<item>26</item>
<item>27</item>
<item>28</item>
<item>29</item>
<item>30</item>
<item>31</item>
<item>32</item>
<item>32</item>
<item>33</item>
<item>34</item>
<item>35</item>
</string-array>
//Code for Recycler View
RRecyclerViewAdapter recipeadapter = new RRecyclerViewAdapter(getResources().getStringArray(R.array.example_array));
RecyclerView rview = (RecyclerView) findViewById(R.id.rrecylerview_recyclerview);
mLinearLayoutManager = new LinearLayoutManager(this);
rview.setLayoutManager(mLinearLayoutManager);
rview.setAdapter(recipeadapter);
//The Code for Recycler View Ends Here
public class RRecyclerViewAdapter extends RecyclerView.Adapter {
TextView textView;
String[] recipelist;
public RRecyclerViewAdapter(String[] r){
recipelist =r;
}
private static final String TAG = "Debug "+RRecyclerViewAdapter.class.getSimpleName();
@NonNull
@Override
public RecipeHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.text_row_item, parent, false);
Log.e (TAG, "in onCreateViewHolder");
return new RecipeHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
textView.setText(recipelist[position]);
Log.e (TAG, "in onBindViewHolder");
}
@Override
public int getItemCount() {
return recipelist.length;
}
public class RecipeHolder extends RecyclerView.ViewHolder {
public RecipeHolder(View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.textView);
Log.e (TAG, "in NoteHolder");
}
}
}
//For Recycler View
implementation "androidx.recyclerview:recyclerview:1.2.0-alpha01"
//implementation "androidx.recyclerview:recyclerview:1.1.0"
// For control over item selection of both touch and mouse driven selection
implementation "androidx.recyclerview:recyclerview-selection:1.1.0-beta01"
//implementation 'com.android.support:recyclerview-v7:28.0.0'
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".RecipeRecycler.RRecyclerView">
<TextureView
android:id="@+id/PlaybackView"
android:layout_width="383dp"
android:layout_height="19dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/AttribView"
android:layout_width="228dp"
android:layout_height="37dp"
android:layout_marginStart="100dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="100dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/PlaybackView" />
<FrameLayout
android:layout_width="409dp"
android:layout_height="415dp"
app:layout_constraintTop_toBottomOf="@+id/AttribView"
tools:layout_editor_absoluteX="1dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rrecylerview_recyclerview"
android:layout_width="404dp"
android:layout_height="278dp"
android:layout_marginTop="10dp"
/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>