не может показать изображение и детали на RecyclerView с помощью firebase - PullRequest
0 голосов
/ 30 сентября 2019

Я попытался получить изображения из базы Firebase с правильной ссылкой URL. RecyclerView продолжает отображать «первую» информацию о Food, которая является cookie-milk-cup:

Это моя структура данных firebase:

all_uploaded_image //directory
|-cookie milk cup 
  |-description: "yes!" //shown successful
  |-image_uri: "content://com.android.providers.media.documents..." //no necessary in this case
  |-name: "cookie milk cup" //shown successful
  |-price: "1.20" //not shown
  |-uploader_uid: "GSsY4tEo5ZZpS8kkJEpWGLCbFmC3" //no necessary in this case
fish n chips //recursive only on cookie milk cup, so nothing appear in here
  |-description: "delicious fc"
  |-image_uri: "content://com.android.providers.media.documents..."
  |-name: "fish n chips"
  |-price: "1.20"
  |-uploader_uid: "GSsY4tEo5ZZpS8kkJEpWGLCbFmC3"

Я использую Android с Java, хочу получитьинформация из firebase, используя фрагмент1014 *

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="4dp"
    android:layout_marginTop="4dp"
    android:layout_marginBottom="4dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <ImageView //icon not shown, white
            android:id="@+id/thumbnail"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_marginStart="8dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@android:drawable/star_big_on" />

            <TextView
                android:id="@+id/foodname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_marginStart="191dp"
                android:layout_marginTop="16dp"
                android:text="Name"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/thumbnail"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/fooddescription"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/foodname"
                android:layout_marginEnd="86dp"
                android:layout_marginBottom="-91dp"
                android:text="Description"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@+id/thumbnail"
                app:layout_constraintTop_toBottomOf="@+id/foodname" />

            <TextView
                android:id="@+id/foodprice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="85dp"
                android:layout_marginEnd="95dp"
                android:text="Price"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.487"
                app:layout_constraintStart_toEndOf="@+id/thumbnail"
                app:layout_constraintTop_toBottomOf="@+id/fooddescription"
                app:layout_constraintVertical_bias="0.0" />

            <Button
                android:id="@+id/fooddetail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginEnd="79dp"
                android:layout_marginBottom="16dp"
                android:background="@color/colorPrimary"
                android:text="Detail"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.496"
                app:layout_constraintStart_toEndOf="@+id/thumbnail"
                app:layout_constraintTop_toBottomOf="@+id/foodprice"
                app:layout_constraintVertical_bias="0.0" />
        </RelativeLayout>
    </androidx.cardview.widget.CardView>

</LinearLayout>

И вот это Activity_main.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"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>


    <LinearLayout
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:autofillHints="email"
            android:layout_margin="15dp"
            android:inputType="textEmailAddress"
            android:hint="Enter Email"
            android:id="@+id/et_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <EditText
            android:layout_margin="15dp"
            android:inputType="textPassword"
            android:hint="Enter Password"
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:layout_margin="15dp"
            android:hint="Register"
            android:id="@+id/btn_register"
            android:layout_width="match_parent"
            android:onClick="click_to_register_new_user"
            android:layout_height="wrap_content" />

        <Button
            android:layout_margin="15dp"
            android:hint="Login"
            android:id="@+id/btn_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />




    </LinearLayout>

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="137dp"
        android:text="@string/reset_string" />

</RelativeLayout>

Наконец, моя модель питания

public class Food {
    public String name;
    public String description;
    public String price;
    public String img_url;
    public String icon;

    public Food() {
        //empty
    }


    public Food(String name, String description, String price, String imageUrl) {
        if (name.trim().equals("")) {
            name = "No Name";
        }
        this.name = name;
        this.description = description;
        this.price = price;
        this.img_url = imageUrl;
    }


    public String get_name() {
        return name;
    }


    public String get_description() {
        return description;
    }


    public String get_price() {
        return price;
    }
    public String get_icon() {
        return icon;
    }

    public String get_url() {
        return img_url;
    }
    public void setPrice(String price) {
        this.price = price;
    }
    public void setImageUrl(String imageUrl) {
        img_url = imageUrl;
    }

    public void set_icon(String icon) {
        this.icon = icon;
    }



}

Я получаю ошибку E / RecyclerView:Адаптер не подключен ; Пропуск макета и не найден установщик / поле для image_uri в классе com.example.hungrystomach.Model.Food [но на самом деле я не хочу, чтобы image_uri показывалось в моем обзоре утилит, поэтому я пропускаю TextView]

У реселлера нет изображения, даже если у меня есть FoodIcon с миниатюрой в FOodAdaper.java. Я пытался в течение трех недель до сих пор без надежды. Я полагаю, чтобы получить всю необходимую мне информацию. Я знаю, что это немного долго, но любые предложения и ответы будут признательны.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...