我是应用开发的新手。我在firebase中链接了两个应用程序,一个用于将图像发送到Firebase存储,图像URL用于Firebase实时数据库,另一个用于使用RecyclerView检索所有图像。第一个应用程序正常运行。但第二个没有做任何事情。它仅显示布局到达。
arrivals.xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="gr.packagename.name.MainActivity"
android:background="@drawable/background">
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="@drawable/logo"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/arrivals_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="144dp" />
</RelativeLayout>
model.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="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:layout_width="100dp"
android:layout_height="200dp"
android:id="@+id/clothesimage"
android:src="@drawable/men"/>
<TextView
android:layout_width="74dp"
android:layout_height="wrap_content"
android:id="@+id/categoryimage"
android:text="category"
android:layout_alignBottom="@+id/clothesimage"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="18sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
到达代码.java
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
public class arrivals extends AppCompatActivity {
DatabaseReference mdatabase;
RecyclerView rv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.arrivals);
mdatabase = FirebaseDatabase.getInstance().getReference().child("Images");
rv = (RecyclerView) findViewById(R.id.arrivals_list);
rv.setHasFixedSize(true);
rv.setLayoutManager(new LinearLayoutManager(this));
}
@Override
protected void onStart(){
super.onStart();
FirebaseRecyclerAdapter<Images, ImageViewHolder> firebaseadapter = new FirebaseRecyclerAdapter<Images, ImageViewHolder>(
Images.class,
R.layout.list_content,
ImageViewHolder.class,
mdatabase
) {
@Override
protected void populateViewHolder(ImageViewHolder viewHolder, Images model, int position) {
viewHolder.setCategory(model.getCategory());
viewHolder.setImageurl(getApplicationContext(), model.getImageurl());
}
};
rv.setAdapter(firebaseadapter);
}
public static class ImageViewHolder extends RecyclerView.ViewHolder{
View mView;
public ImageViewHolder(View itemView){
super(itemView);
mView = itemView;
}
public void setCategory(String category){
TextView categoryimg = (TextView) mView.findViewById(R.id.categoryimage);
categoryimg.setText(category);
}
public void setImageurl(Context ctx, String imageurl){
ImageView img = (ImageView) mView.findViewById(R.id.clothesimage);
Picasso.with(ctx).load(imageurl).into(img);
}
}
}
Images.java代码
public class Images {
private String imageurl;
private String category;
public Images() {
}
public String getImageurl() {
return imageurl;
}
public void setImageurl(String imageurl) {
this.imageurl = imageurl;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
}