我真的很困惑,为什么我的搜索栏没有自动显示结果,它会在我关闭屏幕后显示结果,然后再打开它。截图
这是我的代码:
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_guru);
fotoGuru = findViewById(R.id.fotoguru);
inputsearch = findViewById(R.id.input_search_bar);
mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
arrayList = new ArrayList<DataSetGuru>();
pengajarReference = FirebaseDatabase.getInstance().getReference("Pengajar");
// pengajarReference.keepSynced(true);
LoadListGuru("");
inputsearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.toString()!=null)
{
LoadListGuru(s.toString());
}
else
{
LoadListGuru("");
}
}
});
}
private void LoadListGuru(String data) {
Query query = pengajarReference.orderByChild("kategori").startAt(data).endAt(data+"uf8ff");
options = new FirebaseRecyclerOptions.Builder<DataSetGuru>().setQuery(query,DataSetGuru.class).build();
adapter = new FirebaseRecyclerAdapter<DataSetGuru, FirebaseViewHolder>(options) {
我想知道我怎样才能把这件事做好?或者我在这段代码中做错了什么
也要上传适配器代码。我想你忘记加上这句话了notifyDataSetChanged ()