Firebase RecyclerView图像未显示,其余信息是

问题描述 投票:1回答:1

在我的活动类中,RecyclerView成功从Firebase中检索TextView中的信息并显示它,但是Image View没有使用Picasso显示所需的图像。

我已经尝试过使用Picasso.get()。load(“image”)。into()但它仍然没有显示图像。

包含视图持有者的活动的类是:

public class BeefSamosa extends AppCompatActivity {


   private FirebaseRecyclerAdapter<DataHome, DataHomeViewHolder> firebaseRecyclerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_beef_samosa);
        //Back Button
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Beef Samosa");


        RecyclerView recyclerView = findViewById(R.id.beef_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
        Query query = rootRef.child("DataHome");

        FirebaseRecyclerOptions<DataHome> firebaseRecyclerOptions = new FirebaseRecyclerOptions.Builder<DataHome>()
                .setQuery(query, DataHome.class)
                .build();


        firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<DataHome, DataHomeViewHolder>(firebaseRecyclerOptions) {
            @Override
            protected void onBindViewHolder(@NonNull DataHomeViewHolder dataHomeViewHolder, int position, @NonNull DataHome dataHome) {
                dataHomeViewHolder.setDataHome(dataHome);
            }

            @Override
            public DataHomeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.homedetail, parent, false);

                return new DataHomeViewHolder(view);
            }
        };
        recyclerView.setAdapter(firebaseRecyclerAdapter);

    }

    @Override
    protected void onStart() {
        super.onStart();
        firebaseRecyclerAdapter.startListening();
    }

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

        if (firebaseRecyclerAdapter!= null) {
            firebaseRecyclerAdapter.stopListening();
        }
    }


    @Override
    public boolean onOptionsItemSelected (MenuItem item){
        int id = item.getItemId();

        if(id == android.R.id.home){
            //ends the activity
            this.finish();
        }
        return super.onOptionsItemSelected(item);
    }





    //DataHomeViewHolder class

    private class DataHomeViewHolder extends RecyclerView.ViewHolder {

        private TextView  titletext, description, ingredients, directions;
        private ImageView imagetoo;


        DataHomeViewHolder(View itemView){
            super(itemView);
            imagetoo = (ImageView) itemView.findViewById(R.id.imagetoo);
            titletext = itemView.findViewById(R.id.titletext);
            description = itemView.findViewById(R.id.description);
            ingredients = itemView.findViewById(R.id.ingredients);
            directions = itemView.findViewById(R.id.directions);
        }


        void setDataHome(DataHome DataHome) {
            Picasso.get().load("image").into(imagetoo);
            String titleto = DataHome.getTitle();
            titletext.setText(titleto);
            String descriptionto = DataHome.getDescription();
            description.setText(descriptionto);
            String ingredientsto = DataHome.getIngredients();
            ingredients.setText(ingredientsto);
            String directionsto = DataHome.getDirections();
            directions.setText(directionsto);
        }
    }
}

xml文件是:

<ScrollView

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"
android:layout_marginTop="0dp"
tools:context=".Fragments.Home"
android:orientation="vertical"
    android:scrollbars="vertical"
    android:fadeScrollbars="false"

android:background="@color/colorAccent"
    >


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


        <!-- Image -->
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="140dp"
            android:layout_marginLeft="100dp"
            android:layout_marginTop="0dp"
            android:layout_marginRight="100dp"
            android:id="@+id/imagetoo"
            android:scaleType="centerCrop"
            />



        <!-- Title-->
        <TextView
            android:id="@+id/titletext"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_marginLeft="90dp"
            android:layout_marginTop="30dp"
            android:layout_marginRight="100dp"
            android:textSize="25sp"
            android:textStyle="bold"
            android:textColor="@color/black"
            android:scaleType="fitStart" />


        <View
            android:layout_width="match_parent"
            android:layout_height="4dp"
            android:layout_marginTop="0dp"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="250dp"
            android:background="@color/colorPrimaryDark"
            />

        <!-- Description   -->
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="39dp"
            android:text="Description:"
            android:textColor="@color/black"
            android:textSize="25sp"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:layout_marginLeft="39dp"
            android:textColor="@color/black"
            android:textSize="21sp"
            android:textStyle="normal" />

        <View
            android:layout_width="wrap_content"
            android:layout_height="4dp"
            android:layout_marginLeft="150dp"
            android:layout_marginRight="150dp"
            android:layout_marginTop="35dp"
            android:layout_gravity="bottom"
            android:background="@color/colorPrimaryDark"
            />

        <!-- Ingredients -->

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="39dp"
            android:text="Ingredients:"
            android:textColor="@color/black"
            android:textSize="25sp"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/ingredients"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:layout_marginLeft="39dp"
            android:textColor="@color/black"
            android:textSize="21sp"
            android:textStyle="normal" />

        <View
            android:layout_width="wrap_content"
            android:layout_height="4dp"
            android:layout_marginLeft="150dp"
            android:layout_marginRight="150dp"
            android:layout_marginTop="35dp"
            android:layout_gravity="bottom"
            android:background="@color/colorPrimaryDark"
            />

        <!-- Directions -->

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:layout_marginLeft="39dp"
            android:text="Directions:"
            android:textColor="@color/black"
            android:textSize="25sp"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/directions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:layout_marginLeft="39dp"
            android:textColor="@color/black"
            android:textSize="23sp"
            android:textStyle="normal" />


    </LinearLayout>

</ScrollView>

另一类是:

公共类DataHome {

public DataHome() {}

public String title ,image, description, ingredients, directions;

public DataHome(String title, String image, String description, String ingredients, String directions){
    this.title = title;
    this.image = image;
    this.description = description;
    this.ingredients = ingredients;
    this.directions= directions;
}

public String getTitle() {
    return title;
}

public String getImage() {
    return image;
}

public String getDescription() {
    return description;
}


public String getIngredients() {
    return ingredients;
}


public String getDirections() {
    return directions;
}

}
android firebase firebase-realtime-database picasso firebaseui
1个回答
2
投票

.load()期待你的形象的网址。改变这一行

Picasso.get().load("image").into(imagetoo);

Picasso.get().load(DataHome.getImage()).into(imagetoo);
© www.soinside.com 2019 - 2024. All rights reserved.