为什么arraylist的大小即使已满也为0

我有一个arraylist(user_word)。

我将其发送到CardAdapter2_2_2,它显示了arraylist中的每个项目。

但是user_word.size()返回0。为什么?

 private DatabaseReference databaseReference2 = FirebaseDatabase.getInstance().getReference("kullanici_kelime");
    private ArrayList<User_word> user_words= new ArrayList<>();
        @Override
    public void onStart(){
        super.onStart();
        databaseReference2.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                user_words.clear();
                for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                    User_word user_word= new User_word();
                    user_word.setMean(postSnapshot.child("mean").getValue(String.class)) ;
                    user_word.setName(postSnapshot.child("name").getValue(String.class));
                    user_word.setKey(postSnapshot.child("key").getValue(String.class));
                    user_word.setId(postSnapshot.child("id").getValue(String.class));
                    user_word.setDate(postSnapshot.child("date").getValue(Long.class));
                    user_word.setLevel(postSnapshot.child("level").getValue(int.class));
                    user_words.add(user_word);                }
                adapter.notifyDataSetChanged();            }        });    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.fragment_frag3, container,false);
        Timestamp ts=new Timestamp(System.currentTimeMillis());
        Date date=new Date(ts.getTime());
        Log.e("size", String.valueOf(user_words.size()));// thats my problem
        adapter= new CardAdapter2_2_2(getActivity(),user_words);
        rv.setAdapter(adapter);
                return view;
    }
评论