Я подключил свое приложение к Firestore, и у меня есть строка с именем timey, которая является датой, которая выбрана (не имеет значения, как) и сравнивается со строкой timey в документах Firestore.
Мне удалось заставить приложение отображать вывод Firestore на TextView
, но если у меня есть 2 записи с одинаковой датой, оно всегда выбирает одну и забывает о другой. Поэтому я решил попробовать отобразить данные, используя FirebaseRecyclerAdapter
, который обычно отображает «одну запись даты», но как только я выбираю дату с 2 записями, приложение вылетает. Вот исходный код, есть идеи, как заставить RecyclerView отображать десятки записей с одинаковой датой и размещать их внутри RecyclerView как отдельные записи?
...
passArg - дата, переданная из другого макета.
static String passedArg;
RecyclerView reserveList;
private static final CollectionReference reservationCollection = FirebaseFirestore.getInstance().collection("reservations");
private static Query reservationsQuery;
private FirebaseFirestore db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_page);
textView = findViewById(R.id.textView);
textView2 = findViewById(R.id.textView2);
textView3 = findViewById(R.id.textView3);
passedArg = getIntent().getExtras().getString(MESSAGE_KEY);
textView.setText(passedArg);
reservationsQuery = reservationCollection.whereEqualTo("timey", passedArg);
RecyclerView reserveList = (RecyclerView) findViewById(R.id.reserveList);
reserveList.setLayoutManager(new LinearLayoutManager (this));
FirestoreRecyclerOptions<Reservations> options =
new FirestoreRecyclerOptions.Builder<Reservations>()
.setQuery(reservationsQuery, Reservations.class)
.setLifecycleOwner(this)
.build();
FirestoreRecyclerAdapter<Reservations, ReservationsHolder> adapter = new FirestoreRecyclerAdapter<Reservations, ReservationsHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ReservationsHolder holder, int position, @NonNull Reservations model) {
holder.setName(model.getName());
holder.setTime(model.getTime());
holder.setCountry(model.getCountry());
}
@NonNull
@Override
public ReservationsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ReservationsHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.reservations, parent, false));
}
};
reserveList.setAdapter(adapter);
Если вам нужен дополнительный код, дайте мне знать.
РЕДАКТИРОВАТЬ: Журналы сбоев:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nedim.calendar1, PID: 10342
java.lang.RuntimeException: Could not deserialize object. Failed to convert value of type java.util.Date to String (found in field 'time')
at com.google.android.gms.internal.firebase-firestore.zzko.zzb(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzko.zza(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzko.zza(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzko.zzb(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzko$zza.zza(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzko.zza(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzko.zza(Unknown Source)
at com.google.firebase.firestore.DocumentSnapshot.zza(Unknown Source)
at com.google.firebase.firestore.QueryDocumentSnapshot.zza(Unknown Source)
at com.google.firebase.firestore.DocumentSnapshot.toObject(Unknown Source)
at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(Unknown Source)
at com.firebase.ui.firestore.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:23)
at com.firebase.ui.firestore.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:12)
at com.firebase.ui.common.BaseCachingSnapshotParser.parseSnapshot(BaseCachingSnapshotParser.java:35)
at com.firebase.ui.common.BaseObservableSnapshotArray.get(BaseObservableSnapshotArray.java:52)
at com.firebase.ui.firestore.FirestoreRecyclerAdapter.getItem(FirestoreRecyclerAdapter.java:83)
at com.firebase.ui.firestore.FirestoreRecyclerAdapter.onBindViewHolder(FirestoreRecyclerAdapter.java:125)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6673)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6714)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5647)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5913)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
at android.view.View.layout(View.java:17572)
at android.view.ViewGroup.layout(ViewGroup.java:5656)
at android.support.constraint.ConstraintLayout.onLayout(ConstraintLayout.java:1855)
at android.view.View.layout(View.java:17572)
at android.view.ViewGroup.layout(ViewGroup.java:5656)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17572)
at android.view.ViewGroup.layout(ViewGroup.java:5656)
at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443)
at android.view.View.layout(View.java:17572)
at android.view.ViewGroup.layout(ViewGroup.java:5656)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17572)
at android.view.ViewGroup.layout(ViewGroup.java:5656)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:17572)
at android.view.ViewGroup.layout(ViewGroup.java:5656)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:755)
at android.view.View.layout(View.java:17572)
at android.view.ViewGroup.layout(ViewGroup.java:5656)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2429)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2149)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1306)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6579)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6316)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
W/Firestore: (0.6.6-dev) [OnlineStateTracker]: Could not reach Firestore backend.