我在 Fragment 上创建了一个 Recycler View,将其与 Firebase 连接,但它不会在活动中显示任何内容,也不会从 Firebase 加载。我验证了代码和程序一千次,我真的不知道知道该怎么做,也许这是我的代码或连接中的问题..片段类:public class FragmentUnu extends Fragment { View v; FirebaseDatabase mDatabase; DatabaseReference mRef; RecyclerView mRecycler; RecyclerView.LayoutManager layoutManager; FirebaseRecyclerAdapter < FragmentUnuModel, FragmentUnuViewHolder > adapter; public FragmentUnu() {} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); v = inflater.inflate(R.layout.unu_fragment, container, false); mRecycler = (RecyclerView) v.findViewById(R.id.fragment_unu_recycler); mRecycler.setHasFixedSize(true); layoutManager = new LinearLayoutManager(getActivity()); mRecycler.setLayoutManager(layoutManager); mDatabase = FirebaseDatabase.getInstance(); mRef = mDatabase.getReference("FragmentId"); FirebaseRecyclerOptions < FragmentUnuModel > options = new FirebaseRecyclerOptions.Builder < FragmentUnuModel > () .setQuery(mRef, FragmentUnuModel.class) .build(); adapter = new FirebaseRecyclerAdapter < FragmentUnuModel, FragmentUnuViewHolder > (options) { @NonNull @Override public FragmentUnuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.unu_fragment_item, parent, false); return new FragmentUnuViewHolder(itemView); }我在调试器中没有任何错误
添加回答
举报
0/150
提交
取消