数据没有使用firebase

时间:2017-09-23 02:36:48

标签: android firebase firebase-realtime-database firebase-authentication

我在android studio上使用firebase创建了一个应用程序。使用mobile otp进行身份验证后会出现一个搜索视图。当用户搜索搜索视图时,它将过滤结果并转到回收站视图,依此类推。在第一次启动活动(即,身份验证后的家庭活动)应用程序完美运行。

但我的问题是我的应用程序在一段时间后没有加载数据。其他字段包括searchview也没有用。此外,应用程序在注销后工作,并在发生此问题后再次登录应用程序。

有人知道如何解决它吗?

我的代码是

public class FragmentHome extends Fragment {
private SearchView search;
View v;
DatabaseReference dataRef;
private  FirebaseListAdapter<String> firebaseListAdapter;
ListView mListView;
private TextView text;
ArrayList<String> city=new ArrayList<String>();
private int i=0;
private String data,val,var;
ArrayAdapter<String> adapter;
ProgressBar progressBar;

@Nullable
@Override

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.activity_fragment_home,container,false);
    if (container!=null){
        container.removeAllViews();
    }
    return v;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

progressBar= (ProgressBar) v.findViewById(R.id.search_pro);
search= (SearchView) v.findViewById(R.id.search);
search.onActionViewExpanded();
search.setIconified(false);
search.setInputType(InputType.TYPE_NULL);
search.setQueryHint("Search Docter By City Or Department");
mListView= (ListView) v.findViewById(R.id.mList);
mListView.setVisibility(View.INVISIBLE);

dataRef=FirebaseDatabase.getInstance().getReference().child("Docters");
adapter=new ArrayAdapter<String>(getActivity(), 
android.R.layout.simple_list_item_1, city);
mListView.setAdapter(adapter);
adapter.notifyDataSetChanged();
dataRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    data=dataSnapshot.child("city").getValue(String.class);
    val=dataSnapshot.child("department").getValue(String.class);
    if (!city.contains(data)){
        city.add(data);
    }
    if (!city.contains(val)){
        city.add(val);
    }
    search.setInputType(InputType.TYPE_CLASS_TEXT);
    progressBar.setVisibility(View.GONE);
    adapter.notifyDataSetChanged();

 }
 @Override
 public void onChildChanged(DataSnapshot dataSnapshot, String s) {
    data=dataSnapshot.child("city").getValue(String.class);
    val=dataSnapshot.child("department").getValue(String.class);
    city.add(data);
    city.add(val);
    city.add(var);
    adapter.notifyDataSetChanged();
}

@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {

}

@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}

@Override
public void onCancelled(DatabaseError databaseError) {
}
});
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String text) {

    return false;
}

@Override
public boolean onQueryTextChange(String text) {
    if (!text.isEmpty()){
        adapter.notifyDataSetChanged();
    mListView.setVisibility(View.VISIBLE);
       adapter.getFilter().filter(text);
    }else{
        mListView.setVisibility(View.INVISIBLE);
    }
    return false;
}

});

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long 
id) {
    String itemRef = (String) adapter.getItem(position);
    search.setVisibility(View.INVISIBLE);
    mListView.setVisibility(View.INVISIBLE);
    FragmentTransaction ft=getChildFragmentManager().beginTransaction();
    DocterList fragment=new DocterList();
    Bundle item=new Bundle();
    item.putString("item",itemRef);
    fragment.setArguments(item);
    ft.replace(R.id.activity_fragment_home,fragment);
    ft.addToBackStack(null);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();
}
});
}

0 个答案:

没有答案