【发布时间】:2018-12-28 23:58:52
【问题描述】:
这是我在 Firestore 中的数据 I want to show this name "mouad"
这是我的代码
公共类 SearchActivity 扩展 AppCompatActivity { 私有 RecyclerView mMainList; 私有 FirebaseFirestore mFirestore; 私有列表 usersList; 私有 CustomAdapter 适配器; 编辑文本编辑文本; 按钮 btnSearch; 字符串名称; @覆盖 受保护的无效 onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_firebase); mFirestore = FirebaseFirestore.getInstance(); editText = (EditText) findViewById(R.id.search); btnSearch = (Button) findViewById(R.id.btn); usersList = new ArrayList(); adapterRe = new CustomAdapter(getApplicationContext(), usersList); mMainList = (RecyclerView) findViewById(R.id.recyvle); // mMainList.setHasFixedSize(true); // mMainList.setLayoutManager(new LinearLayoutManager(this)); // mMainList.setAdapter(adapterRe); btnSearch.setOnClickListener(new View.OnClickListener() { @覆盖 公共无效 onClick(查看 v){ SearchUserFirebase(); } }); } 私人无效 SearchUserFirebase() { name = editText.getText().toString(); if(!name.isEmpty()){ 查询 query = mFirestore.collection("Movies").orderBy("name" ).startAt(name).endAt(name + "\uf8ff"); query.addSnapshotListener(new EventListener() { @覆盖 public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) { 如果(e!= null){ Log.d("TAG", "错误:" + e.getMessage()); } ArrayList adsList = new ArrayList(); for(DocumentChange 文档:documentSnapshots.getDocumentChanges()){ if (doc.getType() == DocumentChange.Type.ADDED){ 电影用户 = doc.getDocument().toObject(Movies.class); usersList.add(users); adapterRe.notifyDataSetChanged(); } } Log.d("TAG", "搜索记录数为" + adsList.size()); } }); } } }这是错误
【问题讨论】:
-
请以文本格式添加代码,而不是图片。
-
发布整个活动代码@mouad zizi
-
从注释中删除这一行 - // mMainList.setLayoutManager(new LinearLayoutManager(this)); // mMainList.setAdapter(adapterRe);您的错误将得到解决。
-
这对你有用吗@mouadzizi ?
-
不,它不起作用
标签: java android firebase android-recyclerview google-cloud-firestore