Я пытаюсь разработать приложение, используя firebase.Я хочу использовать панель поиска.Но я не знаю, как это сделать.Я провел некоторые исследования, но не получил результата.
FETCH ACTIVITY
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fetch);
recyclerView = findViewById(R.id.not_list_view);
RecyclerAdapter myAdapter = new RecyclerAdapter(recyclerView, FetchActivity.this, new ArrayList<String>(), new ArrayList<String>());
recyclerView.setAdapter(myAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(FetchActivity.this));
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("Notlar");
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String fileName = dataSnapshot.getKey();
String url = dataSnapshot.getValue(String.class);
((RecyclerAdapter)recyclerView.getAdapter()).update(fileName, url);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
RECYCLER ADAPTER
RecyclerView recyclerView;
Context context;
ArrayList<String> items;
ArrayList<String> urls;
public void update(String name, String url){
items.add(name);
urls.add(url);
notifyDataSetChanged();
}
public RecyclerAdapter(RecyclerView recyclerView, Context context, ArrayList<String> items, ArrayList<String> urls) {
this.recyclerView = recyclerView;
this.context = context;
this.items = items;
this.urls = urls;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(context).inflate(R.layout.not_item,viewGroup,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
viewHolder.title.setText(items.get(i));
}
@Override
public int getItemCount() {
return items.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView title;
Button downButton;
public ViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
downButton = itemView.findViewById(R.id.down_btn);
downButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = getAdapterPosition();
Intent intent = new Intent();
intent.setType(Intent.ACTION_VIEW);
intent.setData(Uri.parse(urls.get(position)));
context.startActivity(intent);
}
});
}
}