0
我正在使用FirebaseListAdapter,它在其構造函數中接受查詢。我正在尋找一種方法,在將它傳遞給構造函數後停止監聽查詢。Android Firebase:停止收聽傳遞到適配器的查詢
這裏就是我創建查詢,並將它傳遞給適配器:
lvSportPics = (ListView) rootView.findViewById(R.id.lv_pics);
final FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference imagesRef = database.getReference().child(Constants.NODE_IMAGES);
Query sportImagesQuery = imagesRef.orderByChild("sport").equalTo(sport);
SportImagesAdapter imgAdapter = new SportImagesAdapter(getActivity(), SportImage.class,
R.layout.list_item_sport_pic, sportImagesQuery);
lvSportPics.setAdapter(imgAdapter);
,這裏是適配器的構造:
public class SportImagesAdapter extends FirebaseListAdapter<SportImage> {
public SportImagesAdapter(Activity activity, Class<SportImage> modelClass, int modelLayout, Query query) {
super(activity, modelClass, modelLayout, query);
}
我知道我可以使用valueEventListner,但我想我需要遍歷結果,並且適配器在傳遞查詢時會自動完成。它運作良好,但它不斷傾聽變化,我想要一種方法來停止傾聽。