试试这个
View view; // declare this globally @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if(view == null){ // initialize if view is null view = inflater.inflate(R.layout.vaccine_fragment_, container, false); recyclerVaccine = (RecyclerView) view.findViewById(R.id.recyclerVaccine); recyclerVaccine.setLayoutManager(new LinearLayoutManager(getActivity())); vaccineList.clear();// i use it to slove the problem.-------------- testData(); vaccineAdapter = new VaccineAdapter(getActivity(), vaccineList); recyclerVaccine.setAdapter(vaccineAdapter); vaccineAdapter.notifyDataSetChanged(); } return view; }