您好我对firebase相对较新,并且我已经看到有针对片段的firebase recyclerview适配器的新实现。我的问题是应用程序不会填充我的recyclerview。这是我的代码
my Fragment
public class DummyFragment extends android.support.v4.app.Fragment {
private FirebaseRecyclerAdapter<Product, ProductViewHolder> mFirebaseAdapter;
private RecyclerView mProduceList = null;
private View rootView;
private Context c;
private LinearLayoutManager manager;
public DummyFragment() {}
public static DummyFragment newInstance() {
DummyFragment fragment = new DummyFragment();
return fragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.dummy_fragment, container, false);
FirebaseApp.initializeApp(c);
mProduceList = rootView.findViewById(R.id.recyclerView);
mProduceList.hasFixedSize();
mProduceList.setLayoutManager(new LinearLayoutManager(getActivity()));
DatabaseReference productRef = FirebaseDatabase.getInstance().getReference().child("Product1");
Query productQuery = productRef.orderByKey();
FirebaseRecyclerOptions productOptions = new FirebaseRecyclerOptions.Builder<Product>().setQuery(productQuery, Product.class).build();
mFirebaseAdapter = new FirebaseRecyclerAdapter<Product, ProductViewHolder>(productOptions) {
@Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View rootView = LayoutInflater.from(c).inflate(R.layout.dummy_fragment, parent, false);
return new ProductViewHolder(rootView);
}
@Override
protected void onBindViewHolder(ProductViewHolder viewHolder, int position, Product model) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
}
};
mProduceList.setAdapter(mFirebaseAdapter);
return rootView;
};
@Override
public void onStart() {
super.onStart();
mFirebaseAdapter.startListening();
}
@Override
public void onStop() {
super.onStop();
mFirebaseAdapter.stopListening();
}
public static class ProductViewHolder extends RecyclerView.ViewHolder {
View mView;
public ProductViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String name) {
TextView post_name = (TextView) mView.findViewById(R.id.productTitle);
post_name.setText(name);
}
public void setDesc(String type) {
TextView post_type = (TextView) mView.findViewById(R.id.productDesc);
post_type.setText(type);
}
}
}
产品类
public class Product {
String Title,Description;
private String image;
public Product(){}
public Product(String title,String desc, String image){
Title = title;
Description = desc;
this.image = image;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
Title = title;
}
public String getDesc() {
return Description;
}
public void setDesc(String desc) {
Description = desc;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
}
和我的清单
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我没有看到为什么它不会填充回收者视图的原因,但我想我错过了一些东西。这是我在控制台中的消息以及W / FA:服务连接失败:ConnectionResult {statusCode = SERVICE_VERSION_UPDATE_REQUIRED,resolution = null,message = null} I / FA:找不到标记管理器,因此不会使用 D / FA:记录事件(FE):screen_view(_vs),Bundle [{firebase_event_origin(_o)= auto,firebase_screen_class(_sc)= MainActivity,firebase_screen_id(_si)= - 7534482907761949523}] V / FA:连接到远程服务 W / GooglePlayServicesUtil:Google Play服务已过期。需要11910000但找到9879470 V / FA:处理排队的服务任务:4 E / FA:丢弃数据。无法发送应用启动 E / FA:无法获得应用实例ID E / FA:无法将当前屏幕发送到服务 E / FA:丢弃数据。无法将事件发送到服务 [03-15 00:06:26.003 5399:5417 D /] HostConnection :: get()建立了新的主机连接0x98c0ac40,tid 5417
答案 0 :(得分:0)
请按照以下方法之一:
答案 1 :(得分:0)