我在我的应用程序中使用了两个回收站视图,一个回收站视图中有直接进入列表的列表,另一个回收站具有firebase数据库。 当我运行我的应用程序时,第一个回收站视图正在工作,但第二个回收站视图未显示,但在日志中它已从Firebase正确检索了数据,请帮助我向回收站视图显示数据。
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#f2f2f2">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recyclerView"
android:orientation="horizontal"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/recyclerView"
android:id="@+id/recyclerMenuView"
android:orientation="vertical"/>
</RelativeLayout>
Mainactivity.java-Firebase Recycler Viw是menu()和getmenu()
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.firebase.FirebaseApp;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
public class MainActivity extends AppCompatActivity {
DatabaseReference reference;
ArrayList<dish> list;
private static final String TAG = "MainActivity";
private ArrayList<String> mCategory = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getCategory();
menu();
}
private void getCategory(){
Log.d(TAG, "Preparing Categories");
mCategory.add("Vagetables");
mCategory.add("Indian Bread");
mCategory.add("Paranthas");
mCategory.add("Starters");
mCategory.add("Snacks");
mCategory.add("Salad");
mCategory.add("Noodles");
mCategory.add("Sandwiches");
mCategory.add("Rice");
mCategory.add("Soups");
mCategory.add("Beverages");
mCategory.add("Yoghurt");
mCategory.add("Papad");
initRecyclerView();
}
private void initRecyclerView(){
Log.d(TAG, "init RecyclerView");
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(layoutManager);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, mCategory);
recyclerView.setAdapter(adapter);
}
private void menu(){
list = new ArrayList<dish>();
Log.d(TAG, "recycler MenuView : Firebase Initialized");
FirebaseApp.initializeApp(this);
reference = FirebaseDatabase.getInstance().getReference().child("dishes");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Log.d(TAG, "onDataChange : called");
for (DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
{
Log.d(TAG,"Adding Menu");
dish p = dataSnapshot1.getValue(dish.class);
Log.d(TAG, "called : " + p);
Log.d(TAG, " : " + dataSnapshot + " : " + dataSnapshot1);
list.add(p);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(MainActivity.this, " Opps....Somethinf Went wrong!", Toast.LENGTH_LONG).show();
}
});
getmenu();
}
private void getmenu(){
Log.d(TAG,"Setting adapter");
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
RecyclerView recyclerMenuView = findViewById(R.id.recyclerMenuView);
recyclerMenuView.setLayoutManager(linearLayoutManager);
MenuAdapter adapter = new MenuAdapter(MainActivity.this, list);
recyclerMenuView.setAdapter(adapter);
}
}
Connection attempt already in progress
V/FA: Activity resumed, time: 1123403393
V/FA: Session started, time: 1123403991
D/FA: Setting user property (FE): _sid, 1562093111
V/FA: Connection attempt already in progress
D/FA: Logging event (FE): session_start(_s), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-756514691701175737, session_id(_sid)=1562093111}]
V/FA: Connection attempt already in progress
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 6
E/FirebaseInstanceId: Failed to resolve target intent service, skipping classname enforcement
E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found.
V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@8162696
D/MainActivity: onDataChange : called
D/MainActivity: Adding Menu
D/MainActivity: called : com.example.myapplication.dish@f142604
D/MainActivity: : DataSnapshot { key = dishes, value = {chilipaneer={dishImage=https://github.com/cb2609/Credit-Management-App/blob/master/food/chilli_paneer.jpg, permission=true, dishname=Chili Paneer, dishrate=Rs.170}, paneertikka={dishImage=https://github.com/cb2609/Credit-Management-App/blob/master/food/paneer_tikka.jpg, permission=true, dishname=Paneer Tikka, dishrate=Rs.150}} } : DataSnapshot { key = chilipaneer, value = {dishImage=https://github.com/cb2609/Credit-Management-App/blob/master/food/chilli_paneer.jpg, permission=true, dishname=Chili Paneer, dishrate=Rs.170} }
D/MainActivity: Adding Menu
D/MainActivity: called : com.example.myapplication.dish@a4197ed
: DataSnapshot { key = dishes, value = {chilipaneer={dishImage=https://github.com/cb2609/Credit-Management-App/blob/master/food/chilli_paneer.jpg, permission=true, dishname=Chili Paneer, dishrate=Rs.170}, paneertikka={dishImage=https://github.com/cb2609/Credit-Management-App/blob/master/food/paneer_tikka.jpg, permission=true, dishname=Paneer Tikka, dishrate=Rs.150}} } : DataSnapshot { key = paneertikka, value = {dishImage=https://github.com/cb2609/Credit-Management-App/blob/master/food/paneer_tikka.jpg, permission=true, dishname=Paneer Tikka, dishrate=Rs.150} }
V/FA: Inactivity, disconnecting from the service```