Java 加载购物车数据时显示空字段

Java 加载购物车数据时显示空字段,java,android,database,firebase-realtime-database,Java,Android,Database,Firebase Realtime Database,我正在做一个食品订购应用程序的项目。在这里,我添加了一个功能,比如用户可以在nav_order部分查看他们的订单。但当我点击这个部分时,它看不到任何类型的数据,但在购物车上是空白的 这是我的订单_layout.xml <?xml version="1.0" encoding="utf-8"?> <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/andr

我正在做一个食品订购应用程序的项目。在这里,我添加了一个功能,比如用户可以在nav_order部分查看他们的订单。但当我点击这个部分时,它看不到任何类型的数据,但在购物车上是空白的

这是我的订单_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    app:cardElevation="4dp"

    >

    <LinearLayout
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:orientation="horizontal"
        android:layout_gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:orientation="vertical"
            android:layout_weight="9"
            android:layout_width="0dp"
            android:layout_height="wrap_content">
            <TextView
                android:text="#111111"
                android:textStyle="bold"
                android:textAllCaps="true"
                android:layout_gravity="center_vertical|start"
                android:layout_marginLeft="10dp"
                android:id="@+id/order_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            </TextView>


            <TextView
                android:text="Status"
                android:textStyle="italic"
                android:textAllCaps="true"
                android:layout_gravity="center_vertical|start"
                android:layout_marginLeft="10dp"
                android:id="@+id/order_status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            </TextView>


            <TextView
                android:text="1234567"
                android:textStyle="italic"
                android:textAllCaps="true"
                android:layout_gravity="center_vertical|start"
                android:layout_marginLeft="10dp"
                android:id="@+id/order_phone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            </TextView>

            <TextView
                android:text="Address"
                android:textStyle="italic"
                android:textAllCaps="true"
                android:layout_gravity="center_vertical|start"
                android:layout_marginLeft="10dp"
                android:id="@+id/order_address"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            </TextView>

        </LinearLayout>



    </LinearLayout>



</androidx.cardview.widget.CardView>
但是我的手推车仍然显示出这样的空白屏幕:

但应该是这样的:

请帮帮我。我已经坚持了三天了。我的项目截止日期就在眼前。拜托,伙计们,帮帮我

@这是我的JSON文件

{
  "Category": {
    "10": {
      "Name": "Noodles",
      "Image": "http://lazeezpune.com/wp-content/uploads/2018/01/chicken-triple-hakka-noodles.jpg"
    },
    "11": {
      "Name": "Snacks",
      "Image": "http://www.rewardsnetwork.com/wp-content/uploads/2017/12/SnacksAsDaypart_2.jpg"
    },
    "01": {
      "Name": "FINGER FOODS",
      "Image": "https://bmexdi064h-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/Italian-Chicken-Wrap-foodiecrush.com-028.jpg"
    },
    "02": {
      "Name": "Western Soup",
      "Image": "https://www.theseasonedmom.com/wp-content/uploads/2018/10/Grandmothers-Hamburger-Soup-TEXT.jpg"
    },
    "03": {
      "Name": "Medifoods delights",
      "Image": "https://www.kindmeal.my/photos/deal/3/358-1030-l.jpg"
    },
    "04": {
      "Name": "Sandwitches",
      "Image": "https://www.landolakes.com/RecipeManagementSystem/media/Recipe-Media-Files/Recipes/Retail/x17/20733-all-american-club-sandwich-600x600.jpg?ext=.jpg"
    },
    "05": {
      "Name": "Pizza",
      "Image": "https://img1.wsimg.com/isteam/stock/2999/:/"
    },
    "06": {
      "Name": "Pasta",
      "Image": "https://www.dinneratthezoo.com/wp-content/uploads/2018/07/penne-alla-vodka-5.jpg"
    },
    "07": {
      "Name": "Chicken",
      "Image": "https://www.fifteenspatulas.com/wp-content/uploads/2018/04/Korean-Chicken-Wings-Fifteen-Spatulas-6.jpg"
    },
    "08": {
      "Name": "Fish",
      "Image": "https://img.taste.com.au/pUWqjn9Q/taste/2016/11/chargrilled-fish-with-green-chilli-coriander-and-coconut-relish-70446-1.jpeg"
    },
    "09": {
      "Name": "Chinese Vegiterian",
      "Image": "https://cdn.eventfinda.co.nz/uploads/events/transformed/1168962-522855-34.jpg?v=6"
    }
  },
  "User": {
    "0988123344": {
      "Name": "Eddydn",
      "Password": "1234"
    },
    "0988123355": {
      "Name": "EddyLEe",
      "Password": "1234"
    },
    "0988123388": {
      "Name": "Tom cruise",
      "Password": "12345"
    }
  },
  "Foods" : {
          "01" : {
            "description" : "",
            "discount" : "0",
            "image" : "https://live.staticflickr.com/65535/48581150471_c644954e41_o.jpg",
            "menuId" : "11",
            "name" : "GINGER PAO",
            "price" : "1000"
          },
          "02" : {
            "description" : "",
            "discount" : "0",
            "image" : "https://live.staticflickr.com/65535/48581150436_dca091792a_o.jpg",
            "menuId" : "11",
            "name" : "COCONUT PAO",
            "price" : "1000"
          },
          "03" : {
            "description" : "",
            "discount" : "0",
            "image" : "https://live.staticflickr.com/65535/48581150341_b2608d308f_o.jpg",
            "menuId" : "11",
            "name" : "RED BEAN PAO",
            "price" : "1000"
          }}}
以下是我的数据库的屏幕截图:

以下是我在SQLite数据库浏览器上的OrderDetailID表:

CREATE TABLE `OrderDetailID` (
    `ID`    INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
    `ProductId` TEXT,
    `ProductName`   TEXT,
    `Quantity`  TEXT,
    `Price` TEXT,
    `Discount`  TEXT
);

在onCreateViewHolder中发布的命名为“OrderViewHolder类代码”的代码中,您返回空值,因此没有附加任何视图,因此没有显示任何内容。

您是否能够从firebase获取数据?@Nik Yes bro。只为那个特定的领域我无法得到它。请帮帮我,兄弟。这个布局顺序是在哪里分配的?@Nik in orderStatus.java类,我已经在我的问题上发布了兄弟。请将您的数据库结构添加为JSON文件或至少是屏幕截图。请回复@AlexMamobro,我已返回itemView.setOnClickListener(此);上面应该有什么变化?请建议检查您在screenshotbro上方发布的FirebaseRecyclerAdapter代码,请您重新检查OrderViewHolder类,我已完成更改,但屏幕仍然为空白。请帮忙?
public class Request{
public class Request{
    private String phone;
    private String name;
    private String address;
    private String total;
    private String status;
    private List<Order>foods;

    public Request() {
    }

    public Request(String phone, String name, String address, String total, List<Order> foods) {
        this.phone = phone;
        this.name = name;
        this.address = address;
        this.total = total;
        this.foods = foods;
        this.status="0"; //Default is 0; 0:Placed , 1:Shipping, 2:Shipped
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public List<Order> getFoods() {
        return foods;
    }

    public void setFoods(List<Order> foods) {
        this.foods = foods;
    }
}
public class Home extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    FirebaseDatabase database;
    DatabaseReference category;
    TextView txtFullName;
    RecyclerView recycler_menu;
    LinearLayoutManager layoutManager;
    FirebaseRecyclerAdapter<Category,MenuViewHolder> adapter;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_home);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("Menu");
        setSupportActionBar(toolbar);
        //Init Firebase
        database = FirebaseDatabase.getInstance();
        category = database.getReference("Category");




        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent cartIntent=new Intent(Home.this,Cart.class);
                startActivity(cartIntent);
            }
        });

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        //Set Name for User
        View headerView = navigationView.getHeaderView(0);
        txtFullName = (TextView)headerView.findViewById(R.id.txtFullName);
        txtFullName.setText(Common.currentUser.getName());

        //Load Menu

        recycler_menu = (RecyclerView)findViewById(R.id.recyler_menu);
        recycler_menu.setHasFixedSize(true);
        layoutManager = new LinearLayoutManager(this);
        recycler_menu.setLayoutManager(layoutManager);
        loadMenu();
    }

        private void loadMenu() {
        FirebaseRecyclerOptions<Category> options;
       // FirebaseRecyclerAdapter<Category,MenuViewHolder> adapter;
        options = new FirebaseRecyclerOptions.Builder<Category>()
                .setQuery(category,Category.class).build();
        adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull MenuViewHolder menuViewHolder, int i, @NonNull Category category) {
                Picasso.get().load(category.getImage())
                        .into(menuViewHolder.imageView, new Callback() {
                            @Override
                            public void onSuccess() {

                            }
                            @Override
                            public void onError(Exception e) {
                                Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
                            }
                        });
                menuViewHolder.textMenuName.setText(category.getName());
                final Category clickItem = category;
                menuViewHolder.setItemClickListener(new ItemClickListener() {
                    @Override
                    public void onClick(View view, int position, boolean isLongClick) {
                        Intent foodList=new Intent(Home.this,FoodList.class);
                        //Because CategoryID is key,so we just get key of this item
                        foodList.putExtra("CategoryId",adapter.getRef(position).getKey());
                        startActivity(foodList);
                    }
                });
            }
            @NonNull
            @Override
            public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_item,parent,false);
                return new MenuViewHolder(view);
            }
        };
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(),2);
        recycler_menu.setLayoutManager(gridLayoutManager);
        adapter.startListening();
        recycler_menu.setAdapter(adapter);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id==R.id.nav_menu) {
        }else if(id==R.id.nav_cart){
            Intent cartIntent=new Intent(Home.this,Cart.class);
            startActivity(cartIntent);
        }else if(id==R.id.nav_order){
            Intent orderIntent=new Intent(Home.this,OrderStatus.class);
            startActivity(orderIntent);
        }else if(id==R.id.logout){

            Intent signIn=new Intent(Home.this,Signin.class);
            signIn.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(signIn);
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}
public class OrderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public TextView txtOrderId,txtOrderStatus,txtOrderPhone,txtOrderAddress;

    private ItemClickListener itemClickListener;

    public OrderViewHolder(@NonNull View itemView) {
        super(itemView);

        txtOrderAddress=itemView.findViewById(R.id.order_address);
        txtOrderId=itemView.findViewById(R.id.order_id);
        txtOrderStatus=itemView.findViewById(R.id.order_status);
        txtOrderPhone=itemView.findViewById(R.id.order_phone);

        itemView.setOnClickListener(this);

    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    @Override
    public void onClick(View v) {

        itemClickListener.onClick(v,getAdapterPosition(),false);

    }
}
{
  "Category": {
    "10": {
      "Name": "Noodles",
      "Image": "http://lazeezpune.com/wp-content/uploads/2018/01/chicken-triple-hakka-noodles.jpg"
    },
    "11": {
      "Name": "Snacks",
      "Image": "http://www.rewardsnetwork.com/wp-content/uploads/2017/12/SnacksAsDaypart_2.jpg"
    },
    "01": {
      "Name": "FINGER FOODS",
      "Image": "https://bmexdi064h-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/Italian-Chicken-Wrap-foodiecrush.com-028.jpg"
    },
    "02": {
      "Name": "Western Soup",
      "Image": "https://www.theseasonedmom.com/wp-content/uploads/2018/10/Grandmothers-Hamburger-Soup-TEXT.jpg"
    },
    "03": {
      "Name": "Medifoods delights",
      "Image": "https://www.kindmeal.my/photos/deal/3/358-1030-l.jpg"
    },
    "04": {
      "Name": "Sandwitches",
      "Image": "https://www.landolakes.com/RecipeManagementSystem/media/Recipe-Media-Files/Recipes/Retail/x17/20733-all-american-club-sandwich-600x600.jpg?ext=.jpg"
    },
    "05": {
      "Name": "Pizza",
      "Image": "https://img1.wsimg.com/isteam/stock/2999/:/"
    },
    "06": {
      "Name": "Pasta",
      "Image": "https://www.dinneratthezoo.com/wp-content/uploads/2018/07/penne-alla-vodka-5.jpg"
    },
    "07": {
      "Name": "Chicken",
      "Image": "https://www.fifteenspatulas.com/wp-content/uploads/2018/04/Korean-Chicken-Wings-Fifteen-Spatulas-6.jpg"
    },
    "08": {
      "Name": "Fish",
      "Image": "https://img.taste.com.au/pUWqjn9Q/taste/2016/11/chargrilled-fish-with-green-chilli-coriander-and-coconut-relish-70446-1.jpeg"
    },
    "09": {
      "Name": "Chinese Vegiterian",
      "Image": "https://cdn.eventfinda.co.nz/uploads/events/transformed/1168962-522855-34.jpg?v=6"
    }
  },
  "User": {
    "0988123344": {
      "Name": "Eddydn",
      "Password": "1234"
    },
    "0988123355": {
      "Name": "EddyLEe",
      "Password": "1234"
    },
    "0988123388": {
      "Name": "Tom cruise",
      "Password": "12345"
    }
  },
  "Foods" : {
          "01" : {
            "description" : "",
            "discount" : "0",
            "image" : "https://live.staticflickr.com/65535/48581150471_c644954e41_o.jpg",
            "menuId" : "11",
            "name" : "GINGER PAO",
            "price" : "1000"
          },
          "02" : {
            "description" : "",
            "discount" : "0",
            "image" : "https://live.staticflickr.com/65535/48581150436_dca091792a_o.jpg",
            "menuId" : "11",
            "name" : "COCONUT PAO",
            "price" : "1000"
          },
          "03" : {
            "description" : "",
            "discount" : "0",
            "image" : "https://live.staticflickr.com/65535/48581150341_b2608d308f_o.jpg",
            "menuId" : "11",
            "name" : "RED BEAN PAO",
            "price" : "1000"
          }}}
CREATE TABLE `OrderDetailID` (
    `ID`    INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
    `ProductId` TEXT,
    `ProductName`   TEXT,
    `Quantity`  TEXT,
    `Price` TEXT,
    `Discount`  TEXT
);