this is my data in Firestore I want to show this name "moad"
This is my code
ublic class SearchActivity extends AppCompatActivity {
private RecyclerView mMainList;
private FirebaseFirestore mFirestore;
private List usersList;
private CustomAdapter adapterRe;
EditText editText;
Button btnSearch;
String name;
@Override
protected void 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() {
@Override
public void onClick(View v) {
SearchUserFirebase();
}
});
}
private void SearchUserFirebase() {
name = editText.getText().toString();
if(!name.isEmpty()){
Query query = mFirestore.collection("Movies").orderBy("name" ).startAt(name).endAt(name + "\uf8ff");
query.addSnapshotListener(new EventListener() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
if (e != null){
Log.d("TAG", "Error : " + e.getMessage());
}
ArrayList adsList = new ArrayList();
for(DocumentChange doc : documentSnapshots.getDocumentChanges()){
if (doc.getType() == DocumentChange.Type.ADDED){
Movies users = doc.getDocument().toObject(Movies.class);
usersList.add(users);
adapterRe.notifyDataSetChanged();
}
}
Log.d("TAG", "no of records of the search is " + adsList.size());
}
});
}
}
}
This is error
1 回答
通常,当您尝试从后台线程设置/通知适配器并从"main"线程(例如
onCreate()
方法内部)中设置 not 时,会出现此错误 .如果您尝试从"delayed"方法中的"delayed"方法通知适配器,则始终会出现此错误 .
要解决这个问题,请在同一个thead中移动适配器的创建,并从for循环中获取以下代码行 .