java - 我的 RecyclerViewer 不显示 View 。我找不到错误。我的源代码在这里

标签 java android

我使用RecyclerViewer来显示数据库中的产品。我使用 FirebaseRecyclerAdapter 获取数据库值。我想在 HomeActivity 中展示我的产品。我尝试了一切,但无法解决此问题,我的产品未显示在 HomeActivity 中。注意=我使用可绘制布局.xml

content_home.xml

<?xml version="1.0" encoding="utf-8"?>
<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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".HomeActivity"
    tools:showIn="@layout/app_bar_home"
    android:background="@android:color/white">

    <android.support.v4.view.ViewPager
    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:id="@+id/view_pager"
    android:layout_width="match_parent"

    android:layout_height="160dp"

    tools:context="com.codinginflow.picassoimagesliderexample.MainActivity">
</android.support.v4.view.ViewPager>

    <TextView
        android:layout_marginTop="15dp"
        android:id="@+id/urunlerimiztxt"
        android:layout_below="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Ürünlerimiz"
        android:textColor="@android:color/black"
        android:textAlignment="center"
        android:textSize="20sp"
        android:textStyle="bold"/>

    <View
        android:id="@+id/urunlerimihr"
        android:layout_margin="15dp"
        android:layout_below="@id/urunlerimiztxt"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:background="#c0c0c0"/>

    <android.support.v7.widget.RecyclerView
        android:layout_below="@+id/urunlerimihr"
        android:id="@+id/urunler_recyclerview"
        android:layout_width="match_parent"
        android:layout_marginLeft="15dp"
     android:layout_marginRight="15dp"
        android:layout_height="wrap_content">

    </android.support.v7.widget.RecyclerView>


</RelativeLayout>

urunlerViewHolder.java

package com.example.hassucuk.ViewHolder;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hassucuk.Interface.itemClickListner;
import com.example.hassucuk.R;

public class urunlerViewHolder  extends RecyclerView.ViewHolder implements View.OnClickListener {


    public ImageView urunresmi;
    public TextView urunadi,urunfiyati,urunkilomiktari;


    private itemClickListner listner;

public urunlerViewHolder(View itemView){
super(itemView);
    urunresmi = (ImageView) itemView.findViewById(R.id.carturun_resim);
    urunadi = (TextView) itemView.findViewById(R.id.carturun_ad);
    urunfiyati = (TextView) itemView.findViewById(R.id.carturun_fiyat);
    urunkilomiktari = (TextView) itemView.findViewById(R.id.carturun_kilomiktari);
}



    public void setItemClickListener(itemClickListner listner){
        this.listner=listner;
    }

    @Override
    public void onClick(View view) {

        listner.onClick(view, getAdapterPosition(),false);

    }
    }


home_product_cart.xml

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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="150dp"
        android:gravity="center_horizontal"
        android:background="@android:color/white"

        android:orientation="horizontal">
        <ImageView
            android:id="@+id/carturun_resim"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:src="@drawable/acili_baton"
            android:layout_weight="1"/>
<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical">
    <TextView
        android:id="@+id/carturun_ad"
        android:textSize="21sp"
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Acılı Baton Sucuk"
        android:textColor="@android:color/black"
       />

    <TextView
android:id="@+id/carturun_fiyat"
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="21sp"
        android:text="53 ₺"
        android:textColor="@android:color/black"
        />
    <TextView
        android:id="@+id/carturun_kilomiktari"
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="21sp"
        android:text="Kilo : 1"
        android:textColor="@android:color/black"
        />
</LinearLayout>

    </LinearLayout>


</android.support.v7.widget.CardView>

HomeActivity.java

    @Override
    protected void onStart() {
        super.onStart();

        FirebaseRecyclerOptions<urunler> options = new FirebaseRecyclerOptions.Builder<urunler>()
                .setQuery(urunlerRootRef,urunler.class)
                .build();

        FirebaseRecyclerAdapter<urunler, urunlerViewHolder> adapter =
                new FirebaseRecyclerAdapter<urunler, urunlerViewHolder>(options) {
                    @Override
                    protected void onBindViewHolder(@NonNull urunlerViewHolder holder, int position, @NonNull  urunler model) {
                        Picasso.get().load(model.getResim()).into(holder.urunresmi);
                        holder.urunadi.setText(model.getAd());
                        holder.urunfiyati.setText(model.getFiyat());
                        holder.urunkilomiktari.setText(model.getFiyat());

                    }

                    @NonNull
                    @Override
                    public urunlerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
                        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_product_cart,parent,false);
                        urunlerViewHolder holder = new urunlerViewHolder(view);
                        return holder;
                    }//xml dosyasını java koduna dönüştürüyor ve o xml görünümünü döndürüyor.
                };
ryclerviewurunler.setAdapter(adapter);
adapter.startListening();
    }

Firebase 数据库 json 文件:

{
  "Sliderlar" : {
    "Haz 17, 201903:36:46" : {
      "image" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Slider%20Resimleri%2Fimage%3A161Haz%2017%2C%20201903%3A36%3A46.jpg?alt=media&token=42ad47df-a361-4247-9263-9a3b86758c64",
      "sliderid" : "Haz 17, 201903:36:46"
    },
    "Haz 17, 201903:37:14" : {
      "image" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Slider%20Resimleri%2Fimage%3A166Haz%2017%2C%20201903%3A37%3A14.jpg?alt=media&token=e47449e0-a1c5-4870-9101-0936265c9cfb",
      "sliderid" : "Haz 17, 201903:37:14"
    },
    "Haz 17, 201903:37:47" : {
      "image" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Slider%20Resimleri%2Fimage%3A164Haz%2017%2C%20201903%3A37%3A47.jpg?alt=media&token=9f681f32-dad3-44c8-a819-e5af02c08605",
      "sliderid" : "Haz 17, 201903:37:47"
    },
    "Haz 17, 201903:37:59" : {
      "image" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Slider%20Resimleri%2Fimage%3A165Haz%2017%2C%20201903%3A37%3A59.jpg?alt=media&token=4dbd866c-0aa4-4673-84cd-dac5f81e4f6f",
      "sliderid" : "Haz 17, 201903:37:59"
    }
  },
  "Urunler" : {
    "Haz 16, 201914:11:19" : {
      "aciklama" : "Acılı Fermente Parmak ",
      "ad" : "Acılı Fermente Parmak Sucuk",
      "fiyat" : "53",
      "resim" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Urun%20resimleri%2Fimage%3A151Haz%2016%2C%20201914%3A11%3A19.jpg?alt=media&token=f3983562-6a71-414f-9eb7-413991d23a63",
      "saat" : "14:11:19",
      "tarih" : "Haz 16, 2019",
      "urunid" : "Haz 16, 201914:11:19"
    },
    "Haz 16, 201914:12:43" : {
      "aciklama" : "Acılı Parmak",
      "ad" : "Acılı Parmak Sucuk",
      "fiyat" : "53",
      "resim" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Urun%20resimleri%2Fimage%3A152Haz%2016%2C%20201914%3A12%3A43.jpg?alt=media&token=fe196025-cab7-4e87-919d-2ce43f23c2e8",
      "saat" : "14:12:43",
      "tarih" : "Haz 16, 2019",
      "urunid" : "Haz 16, 201914:12:43"
    },
    "Haz 16, 201915:16:59" : {
      "aciklama" : "Acısız Fermente Kangal",
      "ad" : "Acısız Fermente Kangal Sucuk",
      "fiyat" : "53",
      "resim" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Urun%20resimleri%2Fimage%3A153Haz%2016%2C%20201915%3A16%3A59.jpg?alt=media&token=39d3a104-8c80-4831-b578-c1804450a32f",
      "saat" : "15:16:59",
      "tarih" : "Haz 16, 2019",
      "urunid" : "Haz 16, 201915:16:59"
    },
    "Haz 16, 201915:17:55" : {
      "aciklama" : "Acısız Kangal",
      "ad" : "Acısız Kangal Sucuk",
      "fiyat" : "53",
      "resim" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Urun%20resimleri%2Fimage%3A154Haz%2016%2C%20201915%3A17%3A55.jpg?alt=media&token=24a41db6-d25b-480d-ba86-a4bb1fca6983",
      "saat" : "15:17:55",
      "tarih" : "Haz 16, 2019",
      "urunid" : "Haz 16, 201915:17:55"
    },
    "Haz 16, 201915:18:49" : {
      "aciklama" : "Acılı Baton",
      "ad" : "Acılı Baton Sucuk",
      "fiyat" : "53",
      "resim" : "https://firebasestorage.googleapis.com/v0/b/has-sucuk.appspot.com/o/Urun%20resimleri%2Fimage%3A155Haz%2016%2C%20201915%3A18%3A49.jpg?alt=media&token=17cd8c5e-1bd2-4118-947a-32d8135fc3a0",
      "saat" : "15:18:49",
      "tarih" : "Haz 16, 2019",
      "urunid" : "Haz 16, 201915:18:49"
    }
  },
  "Users" : {
    "05531530440" : {
      "loginpassword" : "123456",
      "loginphone" : "05531530440",
      "name" : "Fatih İnci",
      "role" : "admin"
    },
    "05531530450" : {
      "loginpassword" : "123456",
      "loginphone" : "05531530450",
      "name" : "deneme 1",
      "role" : "user"
    }
  }
}

最佳答案

在设置适配器之前,您需要在 RecyclerView 上设置 LayoutManager

对于垂直滚动的项目列表,请使用:

ryclerviewurunler.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));

关于java - 我的 RecyclerViewer 不显示 View 。我找不到错误。我的源代码在这里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56629616/

相关文章:

android - 错误 :Could not read cache value from '/Users/gsp/.gradle/daemon/2.10/registry.bin'

Android:在设备桌面上显示图标

android - 如何将位图图像设置为按钮背景图像

Android Studio Canary 4 将红线放在 AppCompatActivity 类的任何方法下,尽管它可以编译

java - 如何使用 JSP 列出服务器目录的内容?

java - 加快矩阵查找速度

java - 如何获取 Websphere 6.1 端口号

java - 关于嵌套 Java try/finally 代码三明治的建议

Java 线程安全 - 了解同步的需要

android - 碰撞在 Box2D 与 Cocos2d Android 中无法正常工作