我有一个具有动态大小的数组,我想加载的所有元素 使用适配器在RecyclerView中排列数组,从左到右,从右到 向左滑动使用RecyclerView数组的每个元素,我添加了 在适配器视图中使用FrameLayout并创建一个片段和该片段 如果适配器中数组的每个索引都映射到帧布局 在onBindViewHolder(ViewHolder持有人,int位置)上滑动时 这不适用于滑块,我可以使用视图寻呼机,但不能使用视图寻呼机 在滑动过程中收听每个索引,这就是为什么我使用recyclerview的原因 帮助将数据以“滑块”的形式加载到“回收站”视图中,也有助于加载 刷卡时突然碎裂
这是适配器代码
ArrayList<CourseLessonDetailsData> mCourseLessonDetailsDataList = new ArrayList<>();
CourseDetailsActivity mActivity;
FragmentManager mFragmentManager;
public SwipeRecyclerViewAdapter(ArrayList<CourseLessonDetailsData> _courseLessonDetailsDataList , CourseDetailsActivity _activity, FragmentManager fragmentManager) {
mActivity = _activity;
mCourseLessonDetailsDataList = _courseLessonDetailsDataList;
mFragmentManager = fragmentManager;
}
@Override
public SwipeRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Create a new view by inflating the row item xml.
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.swipe_course_detail_recycler_item_view, parent, false);
// Set the view to the ViewHolder
return new SwipeRecyclerViewAdapter.ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
SwipeFragment swipeFragment = new SwipeFragment();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("course_lesson_array", mCourseLessonDetailsDataList);
bundle.putString("position", position + "");
swipeFragment.setArguments(bundle);
fragmentTransaction.add(R.id.swipe_recycler_view_frame_layout, swipeFragment);
fragmentTransaction.commit();
}
@Override
public int getItemCount() {
return mCourseLessonDetailsDataList.size();
}
// Create the ViewHolder class to keep references to your views public class ViewHolder extends RecyclerView.ViewHolder{
public FrameLayout swipe_recycler_view_frame_layout;
/*
* Constructor
* @param v The container view which holds the elements from the row item xml
*/
public ViewHolder(View v) {
super(v);
swipe_recycler_view_frame_layout = v.findViewById(R.id.swipe_recycler_view_frame_layout);
}
}