Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.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
Arrarylist大小为0,android中带有静态recyclerview列表_Android_Android Recyclerview - Fatal编程技术网

Arrarylist大小为0,android中带有静态recyclerview列表

Arrarylist大小为0,android中带有静态recyclerview列表,android,android-recyclerview,Android,Android Recyclerview,您好,在下面的代码适配器中,我在调试代码时定义了一个列表,它为我提供的患者大小为0。现在,所有列表项都设置为recyclerview以显示项目列表。但没有显示任何内容 实际上,模型类包含一个数据,但它给我的是0 谁能帮我重新爱上它 list_item.java: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas

您好,在下面的代码适配器中,我在调试代码时定义了一个列表,它为我提供的患者大小为0。现在,所有列表项都设置为recyclerview以显示项目列表。但没有显示任何内容

实际上,模型类包含一个数据,但它给我的是0

谁能帮我重新爱上它

list_item.java:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content"
    android:background="@color/bg"
    android:id="@+id/contact_card"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchorGravity="center"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/card_details">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:id="@+id/cards"
                android:background="@color/bg">


                <androidx.cardview.widget.CardView
                    android:id="@+id/cardView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:cardBackgroundColor="@color/slivergray"
                    app:cardCornerRadius="5dp"
                    app:cardElevation="4dp"
                    app:cardUseCompatPadding="true">
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:id="@+id/suject_ids"
                        android:background="@color/white">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                            android:padding="2dp"
                            android:layout_marginTop="1dp">
                            <de.hdodenhof.circleimageview.CircleImageView
                                android:id="@+id/doctor_profile"
                                android:layout_width="96dp"
                                android:layout_height="96dp"
                                android:src="@drawable/ic_round_account_circle_24"
                                app:civ_border_width="2dp"
                                app:civ_border_color="@color/theme"/>
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:layout_marginTop="4dp"
                                android:orientation="vertical">
                                <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:orientation="horizontal">
                                <TextView
                                    android:id="@+id/doctor_name"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/names"
                                    android:paddingLeft="16dp"
                                    android:text="Dr. Regina Joseph"
                                    android:layout_weight="1"
                                    android:textAllCaps="true"
                                    android:textColor="@color/theme"
                                    android:textSize="14sp"
                                    android:textStyle="bold"/>
                                    <TextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="Booking : Scheduled"
                                        android:padding="2dp"
                                        android:textColor="@color/theme">

                                    </TextView>
                                </LinearLayout>
                                <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:orientation="horizontal">
                                <TextView
                                    android:id="@+id/age"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/doctor_name"
                                    android:paddingLeft="16dp"
                                    android:text="Age : 26"
                                    android:textStyle="bold"
                                    android:layout_weight="1"
                                    android:textAllCaps="false"
                                    android:textColor="@color/theme"
                                    android:textSize="14sp" />
                                    <TextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="Booking ID: 10"
                                        android:padding="2dp"
                                        android:textColor="@color/theme">
                                    </TextView>
                                </LinearLayout>
                                <TextView
                                    android:id="@+id/date"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/doctor_name"
                                    android:paddingLeft="16dp"
                                    android:text="Today,25 Dec"
                                    android:textStyle="bold"
                                    android:layout_weight="1"
                                    android:textAllCaps="false"
                                    android:textColor="@color/theme"
                                    android:textSize="14sp" />
                                <TextView
                                    android:id="@+id/time"
                                    style="@style/Base.TextAppearance.AppCompat.Subhead"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/doctor_name"
                                    android:paddingLeft="16dp"
                                    android:text="11:00 - 11:15 AM"
                                    android:textStyle="bold"
                                    android:layout_weight="1"
                                    android:textAllCaps="false"
                                    android:textColor="@color/theme"
                                    android:textSize="14sp" />

                                <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:padding="5dp"
                                    android:weightSum="2"
                                    android:orientation="horizontal">
                                    <TextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="View Details"
                                        android:layout_below="@+id/consultationFees"
                                        android:layout_weight="1"
                                        android:layout_gravity="center"
                                        android:gravity="center"
                                        android:textAllCaps="false"
                                        android:textColor="@color/theme">
                                    </TextView>
                                    <TextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="Cancel Appointment"
                                        android:id="@+id/select"
                                        android:padding="5dp"
                                        android:layout_below="@+id/consultationFees"
                                        android:layout_weight="1"
                                        android:layout_gravity="right"
                                        android:gravity="right"
                                        android:textAllCaps="false"
                                        android:textColor="@color/theme">
                                    </TextView>
                                </LinearLayout>
                            </LinearLayout>

                        </LinearLayout>


                    </RelativeLayout>
                </androidx.cardview.widget.CardView>

            </LinearLayout>



        </LinearLayout>


    </FrameLayout>

</RelativeLayout>

PatientAdapter.java:

public class PatientAdapter extends RecyclerView.Adapter<PatientAdapter.MyViewHolder> {

    private Context mContext;
    private List<PatientModel> patientModels;

    public PatientAdapter(List<PatientModel> patientModels) {
        this.patientModels=patientModels;
    }

    @NonNull
    @Override
    public PatientAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(R.layout.patient_list, parent, false);
        PatientAdapter.MyViewHolder holder = new PatientAdapter.MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull PatientAdapter.MyViewHolder holder, int position) {
        holder.doctor_name.setText(patientModels.get(position).getPatient_name());
    }

    @Override
    public int getItemCount() {
        Log.d("size of the patient", String.valueOf(patientModels.size()));
        return patientModels.size();

    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView doctor_name;

        public MyViewHolder(View itemView) {
            super(itemView);
            doctor_name=itemView.findViewById(R.id.doctor_name);

        }
    }
}
公共类PatientAdapter扩展了RecyclerView.Adapter{ 私有上下文; 私有列表模型; 公共PatientAdapter(列出patientModels){ this.patientModels=patientModels; } @非空 @凌驾 public PatientAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup父级,int-viewType){ mContext=parent.getContext(); LayoutFlater充气机=LayoutFlater.from(mContext); 视图=充气机。充气(R.layout.patient_list,parent,false); PatientAdapter.MyViewHolder=新PatientAdapter.MyViewHolder(视图); 报税表持有人; } @凌驾 public void onBindViewHolder(@NonNull PatientAdapter.MyViewHolder,int位置){ holder.doctor\u name.setText(patientModels.get(position.getPatient\u name()); } @凌驾 public int getItemCount(){ Log.d(“患者的大小”,String.valueOf(patientModels.size()); 返回patientModels.size(); } 公共类MyViewHolder扩展了RecyclerView.ViewHolder{ TextView医生姓名; 公共MyViewHolder(查看项目视图){ 超级(项目视图); doctor\u name=itemView.findViewById(R.id.doctor\u name); } } } ViewPatientsFragment.java:

public class ViewPatientsFragment extends Fragment{
    private ArrayList<PatientModel> patientModelsList;
    public View_PatientList() {
        // Required empty public constructor
    }

    private RecyclerView recyclerPatient;

    private PatientAdapter patientAdapter;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.view_patientlist, container, false);

        recyclerPatient=rootView.findViewById(R.id.recyclerPatient);
        patientModelsList=new ArrayList<>();
        patientAdapter=new PatientAdapter(patientModelsList);
        recyclerPatient.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        recyclerPatient.setAdapter(patientAdapter);

        return rootView;
    }
}
公共类ViewPatientsFragment扩展了片段{
私人ArrayList患者模型列表;
公共视图_PatientList(){
//必需的空公共构造函数
}
私人废物回收公司;
私人病人接受器;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图根视图=充气机。充气(R.layout.View\u patientlist,container,false);
recyclerPatient=rootView.findViewById(R.id.recyclerPatient);
PatientModelList=新建ArrayList();
patientAdapter=新的patientAdapter(PatientModelList);
setLayoutManager(新的LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false));
recyclerPatient.setAdapter(patientAdapter);
返回rootView;
}
}

问题在于,正如您所看到的,您没有向阵列插入任何内容,而是初始化阵列,然后将其放入适配器中

patientModelsList=new ArrayList<>(); <-- EMPTY
patientAdapter=new PatientAdapter(patientModelsList); <-- SENDING AN EMPTY LIST

--What you need--
patientModelsList.add(YOUR OBJECT HERE)
patientModelList.add(YOUR OBJECT HERE)
--And then call--
patientAdapter=new PatientAdapter(patientModelsList);

问题在于,正如您所看到的,您没有向数组插入任何内容,而是初始化数组,然后将其放入适配器中

patientModelsList=new ArrayList<>(); <-- EMPTY
patientAdapter=new PatientAdapter(patientModelsList); <-- SENDING AN EMPTY LIST

--What you need--
patientModelsList.add(YOUR OBJECT HERE)
patientModelList.add(YOUR OBJECT HERE)
--And then call--
patientAdapter=new PatientAdapter(patientModelsList);

请上载使用的类it@ATP请看一看如何向数组插入值?
patientModelList
为空…您不能仅在recyclerview中使用空数组显示布局。。您需要将一些数据插入回收器阵列请上载使用的类it@ATP请看一看如何向数组插入值?
patientModelList
为空…您不能仅在recyclerview中使用空数组显示布局。。您需要将一些数据插入回收器阵列