Ich habe eine Listenansicht erstellt, die mit Adapter anpassen und ich möchte die Listenansicht filtern, indem Sie Editiertext eingeben. Allerdings fand ich es schwierig, da ich alle Daten von Firebase bekomme. Wie kann ich die Daten nach Namen filtern? Welchen Code muss ich hinzufügen?ListView Filterdaten in Edittext
Es ist meine Haupttätigkeit
private void readFirebaseData() {
FirebaseDatabase.getInstance().getReference("account").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
uid = (String) snapshot.child("uid").getValue();
contactNo = (String) snapshot.child("contactNo").getValue();
email = (String) snapshot.child("email").getValue();
name = (String) snapshot.child("name").getValue();
Shop shops = new Shop(uid, contactNo, email, name);
shopListAdapter adapter = new shopListAdapter(getActivity(), shop);
adapter.add(shops);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
}
private void filter() {
searcher.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
adapter.getFilter().filter(s);
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
Es ist meine Adapter-Klasse ist
public class shopListAdapter extends ArrayAdapter<Shop> {
private ArrayList<Shop> shops;
Filter filter;
public shopListAdapter(Context context, ArrayList<Shop> shops) {
super(context, 0, shops);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Shop shops = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item, parent, false);
}
TextView name = (TextView) convertView.findViewById(R.id.txtName);
TextView address = (TextView) convertView.findViewById(R.id.txtAdd);
name.setText(shops.getShopName());
address.setText(shops.getAddress());
return convertView;
}
also wenn ich daten von firebase füge ich füge es in Vector? – kings077712
U kann Vector oder Array-Liste verwenden. – Prosanto
es funktioniert nicht können Sie ein wenig mehr erklären oder meinen Code verwenden? – kings077712