setImageResource () не получает изображение через Firebase - PullRequest
0 голосов
/ 27 марта 2020

Я использую переработчик для моего проекта Firebase. Первоначально при нажатии на карту рециркуляции будет отображаться полная информация о карте. Но все работает нормально до появления карт. При нажатии на карту отображается вся информация, кроме изображения. Изменены имена классов здесь для лучшего понимания. Отображается все, кроме изображения.

ImageAdapter.class

package com.example.finalapkx;

import android.content.Context;
import android.content.Intent;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.squareup.picasso.Picasso;

import java.util.List;

public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
    public Context mContext;
    private List<Upload> mUploads;

    public ImageAdapter(Context context, List<Upload> uploads){
        mContext = context;
        mUploads = uploads;
    }

    @NonNull
    @Override
    public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(mContext).inflate(R.layout.image_item,parent,false);
        return new ImageViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
        final Upload uploadCurrent = mUploads.get(position);
        holder.textviewName.setText(uploadCurrent.getName());
        Picasso.get()
                .load(uploadCurrent.getImageUrl())
                .placeholder(R.mipmap.ic_launcher)
                .fit()
                .centerInside()
                .into(holder.imageViewand);

        holder.textviewDate.setText(uploadCurrent.getDate());

      holder.relativeLay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext,Main3Activityand_retrieve_Detail.class);
                intent.putExtra("EventName",uploadCurrent.getName());
               intent.putExtra("ImageAndroid", uploadCurrent.getImageUrl());
                intent.putExtra("Date",uploadCurrent.getDate());
                intent.putExtra("Profile",uploadCurrent.getProfile());
                intent.putExtra("TargetedStudents",uploadCurrent.getTargetedStu());
                intent.putExtra("RegistrationLink",uploadCurrent.getReglink());
                intent.putExtra("OptionalLink",uploadCurrent.getReglinktwo());
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mUploads.size();
    }

    public class ImageViewHolder extends RecyclerView.ViewHolder{
        public TextView textviewName;
        public ImageView imageViewand;
        public TextView textviewDate;
        RelativeLayout relativeLay;
        public TextView textViewProfile;
        public TextView textViewReglink;
        public TextView textViewReglinktwo;
        public ImageViewHolder(View itemView){
            super(itemView);
            textviewName = itemView.findViewById(R.id.androideventname);
            imageViewand = itemView.findViewById(R.id.androiduploadedimage);
            textviewDate = itemView.findViewById(R.id.androideventdate);
            relativeLay = itemView.findViewById(R.id.layoutRelative);


        }
    }

}

Detailactivity.class

package com.example.finalapkx;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextClock;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

public class Main3Activityand_retrieve_Detail extends AppCompatActivity {
    ImageView androidimgdetail;
    TextView andname,anddate,andprof,andreg,andregtwo,andTargetedStu;
    String adname, addate,adprof,adreg,adregtwo,adtargetedstu;
    int adimag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3_activityand_retrieve__detail);
        androidimgdetail = findViewById(R.id.androiduploadedimage);
        andname = findViewById(R.id.andeventdetailid);
        anddate = findViewById(R.id.anddatedetailid);
        andTargetedStu = findViewById(R.id.andtargeteddetail);
        andprof = findViewById(R.id.andprofiledetail);
        andreg = findViewById(R.id.andreglinkdetail);
        andregtwo = findViewById(R.id.andreglinkdetail2);
        adname = getIntent().getStringExtra("EventName");
        addate = getIntent().getStringExtra("Date");
        adprof = getIntent().getStringExtra("Profile");
        adtargetedstu = getIntent().getStringExtra("TargetedStudents");
        adreg = getIntent().getStringExtra("RegistrationLink");
        adregtwo = getIntent().getStringExtra("OptionalLink");
        adimag = getIntent().getIntExtra("ImageAndroid",0);
        andname.setText(adname);
        anddate.setText(addate);
        andTargetedStu.setText(adtargetedstu);
        andprof.setText(adprof);
        andreg.setText(adreg);
        andregtwo.setText(adregtwo);
        androidimgdetail.setImageResource(adimag);
    }
}

активность_деталь

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".Main3Activityand_retrieve_Detail">
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

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

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

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:background="@drawable/background_gradient"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="0dp" />
            <ImageView
                android:id="@+id/fake2"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />

        </LinearLayout>
        <LinearLayout
            android:layout_marginTop="50dp"
            android:id="@+id/layoutInput"
            android:layout_marginRight="20dp"
            android:layout_marginLeft="20dp"
            android:layout_centerHorizontal="true"
            android:background="@drawable/background_white"
            android:padding="20dp"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <TextView
            android:layout_margin="8dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18dp"
            android:text="Event Name"
            android:fontFamily="@font/mpb"
            android:textColor="#000">

        </TextView>
            <TextView
                android:id="@+id/andeventdetailid"
                android:layout_margin="8dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="Event Name"
                android:fontFamily="@font/mpb"
                android:textColor="#000">

            </TextView>

            <TextView
                android:layout_margin="8dp"
                android:id="@+id/anddatedetailid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="Date:"
                android:fontFamily="@font/mpb"
                android:textColor="#000">

            </TextView>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="Resource Person:"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp">

            </TextView>
            <ImageView
                android:layout_margin="8dp"
                android:id="@+id/androiduploadedimage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp">

            </ImageView>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="Profile"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                >

            </TextView>
            <TextView
                android:id="@+id/andprofiledetail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="NULL"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                >

            </TextView>
            <TextView

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="Targeted Students:"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp">

            </TextView>



            <TextView
                android:id="@+id/andtargeteddetail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="NULL"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                >

            </TextView>
            <TextView

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="Registration Link:"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp">

            </TextView>


            <TextView
                android:id="@+id/andreglinkdetail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="NULL"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp">

            </TextView>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="Optional Link:"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                >

            </TextView>


            <TextView
                android:id="@+id/andreglinkdetail2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18dp"
                android:text="NULL"
                android:fontFamily="@font/mpb"
                android:textColor="#000"
                android:layout_margin="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="8dp"
                >

            </TextView>








        </LinearLayout>
        </RelativeLayout>
        </LinearLayout>
    </ScrollView>

    </ScrollView>

1 Ответ

1 голос
/ 27 марта 2020

setImageResouse используется для доступа к файлам из папки Drawable. Чтобы получить изображения из Firebase, используйте Piccasso

Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);

и добавьте это в свою зависимость

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