Firebase查询结果在ListView UI和RecyclerView UI中 [英] Firebase query result in ListView UI and RecyclerView UI
问题描述
我无法填充ListView。
ArrayList< String> mItems = new ArrayList<>();
ArrayAdapter mAdapter;
ListView mRecyclerView;
FirebaseListAdapter< String> fireAdapter = new FirebaseListAdapter< String>(){
@Override
protected void populateView(View view,String s){
//填充视图
}
};
在上面的代码中,我无法写出构造函数,
FirebaseListAdapter< String> fireAdapter = new FirebaseListAdapter< String>(this,String.class,
android.R.layout.simple_list_item_1,mEmployRef){
@Override
protected void populateView(View view,String s){
//填充视图
}
};
当我用构造函数写上面的代码时,它说:
无法解析构造函数'FirebaseListAdapter(anonymous android.view.View.OnClickListener,java.lang.Class,int,com.google.firebase.database.DatabaseReference)'
我如何解决这个问题?当我尝试使用RecyclerView时,会出现类似的问题。
当Firebase升级时,我遇到了这个问题,取出构造函数的错误是改变这一点:
Firebase rootRef = new Firebase(https://< your-app> ; .firebaseio.com /);
对此:
DatabaseReference rootRef = FirebaseDatabase.getInstance()。getReference();
然后使用rootRef作为构造函数的第四个参数。
这里是从以前的firebase升级到当前的链接:
https://firebase.google.com/support/guides/firebase-android#import_your_project_to_the_new_firebase_console_numbered
另外,升级您的sdk。希望这可以解决您的问题
I am trying to create a Firebase database to store employee information and then when an address is queried, all the employees staying in that particular area should be displayed in a ListView or a RecyclerView however, I am having the following problem:
I am unable to populate the ListView.
ArrayList<String> mItems = new ArrayList<>();
ArrayAdapter mAdapter;
ListView mRecyclerView;
FirebaseListAdapter<String> fireAdapter = new FirebaseListAdapter<String>() {
@Override
protected void populateView(View view, String s) {
//populate view
}
};
In the above code, I am unable to write the constructor so that it becomes,
FirebaseListAdapter<String> fireAdapter = new FirebaseListAdapter<String>(this,String.class,
android.R.layout.simple_list_item_1,mEmployRef) {
@Override
protected void populateView(View view, String s) {
//populate view
}
};
When I write the above code with the constructor, it says,
Cannot resolve constructor 'FirebaseListAdapter(anonymous android.view.View.OnClickListener, java.lang.Class, int, com.google.firebase.database.DatabaseReference)'
How do I resolve this? A similar problem occurs when I try to use a RecyclerView.
I was having this problem when Firebase upgraded and what i did to get out of the constructor error was change this:
Firebase rootRef = new Firebase("https://<your-app>.firebaseio.com/");
to this:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
then use the rootRef as the fourth parameter on the constructor.
here is a link for upgrading from the previous firebase to the current: https://firebase.google.com/support/guides/firebase-android#import_your_project_to_the_new_firebase_console_numbered
Also, upgrade your sdk. Hope this solves your problem
这篇关于Firebase查询结果在ListView UI和RecyclerView UI中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!