无法显示adapter_Firebase中的所有图像(图像网址 - arraylist)

时间:2018-06-18 04:26:51

标签: java android firebase firebase-realtime-database picasso

这是我的适配器类,从Blog.class获取setter和getter,并从主活动调用适配器类,如下所示!从主要活动调用适配器类的代码

 mdatabaseReference = 
FirebaseDatabase.getInstance().getReference().child("Blog");
    userdatabaseReference= 
FirebaseDatabase.getInstance().getReference().child("Users");
    likesdatabaseReference= FirebaseDatabase.getInstance().getReference().child("Likes");
    mDBRefSetup = FirebaseDatabase.getInstance().getReference().child("Users");
    mquery = mdatabaseReference.orderByChild("time");
    mdatabaseReference.keepSynced(true);
    userdatabaseReference.keepSynced(true);

firebaseAuth.addAuthStateListener(authStateListener);
            mProgressbar.setMessage("Fetching .....");
            mProgressbar.show();
            mProgressbar.dismiss();
            list = new ArrayList<>();
            adapter = new MyCustomAdapter(this,list,firebaseAuth,mdatabaseReference,likesdatabaseReference);
            recyclerView = (RecyclerView) findViewById(R.id.blog_list);
            recyclerView.setLayoutManager(new LinearLayoutManager(this));
            recyclerView.setAdapter(adapter);

              mchildEventListener = new ChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                    mProgressbar.dismiss();
                    String j = dataSnapshot.getKey();
                    Log.v("GETKEYZZZ", j);
                   Blog friendlyMessage = dataSnapshot.getValue(Blog.class);

                   friendlyMessage.setPostkey(j);

                    list.add(friendlyMessage);
                    adapter.notifyDataSetChanged();

                }

                public void onChildChanged(DataSnapshot dataSnapshot, String s) {}
                public void onChildRemoved(DataSnapshot dataSnapshot){}
                public void onChildMoved(DataSnapshot dataSnapshot, String s) {}
                public void onCancelled(DatabaseError databaseError) {}
            };
            mquery.addChildEventListener(mchildEventListener);

这是我的Adapter类,使用图片网址arryalist显示用户名,时间,描述和图像,但显示一个图像。         公共类MyCustomAdapter扩展了RecyclerView.Adapter {

Context context;
ArrayList<Blog> list;
List <String> imageUrls;
LayoutInflater inflator;
int lastPosition = 1;
boolean mprogressLike = true,mprogressview = true;
DatabaseReference likeDatabaseReference;
FirebaseAuth firebaseAuth;
DatabaseReference blogDatabaseReference;


public MyCustomAdapter(Context context, ArrayList<Blog> list,FirebaseAuth firebaseAuth,DatabaseReference blogDatabaseReference, DatabaseReference likeDatabaseReference) {

    this.context=context;
    this.list=list;
    inflator=LayoutInflater.from(context);
    this.likeDatabaseReference=likeDatabaseReference;
    this.firebaseAuth=firebaseAuth;
    this.blogDatabaseReference=blogDatabaseReference;
}
@Override
public myviewholder onCreateViewHolder(ViewGroup parent, int position) {

    View v=inflator.inflate(R.layout.posts,parent,false);
    myviewholder holder=new myviewholder(v);
    return holder;
}

@Override
public void onBindViewHolder(final myviewholder holder, int position) {


    final Blog p=list.get(position);
    holder.title.setText(p.getTitle());
    holder.username.setText(p.getUsername());
    holder.viewno.setText(p.getTimestamp());



    for(Blog model : list) {
        imageUrls = new ArrayList<>();;
        imageUrls.addAll(model.getUrl());

        Log.v("IMURLSSS", String.valueOf(imageUrls));




    }
    for(int i=0; i<imageUrls.size(); i++)
    {

        Picasso.with(context).load(imageUrls.get(i)).into(holder.imageview);
        Log.v("IMGGPOS", imageUrls.get(i));

    }

    Picasso.with(context).load(p.getImage()).into(holder.userdp);
    final  String post_key = p.getUid().toString();
    Log.v("POST", post_key);
    final  String current_user= firebaseAuth.getCurrentUser().getUid();
    Log.v("CURRENT", current_user);
    if(post_key.equals(current_user)){
        holder.over.setVisibility(View.VISIBLE);
    }else{
        holder.over.setVisibility(View.INVISIBLE);
    }







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

public class myviewholder extends RecyclerView.ViewHolder 
{

    TextView title,desc,username,likeno,viewno;
    ImageView imageview,userdp, over, comments, likes;
    ImageButton likebtn,viewbtn;

    public myviewholder(View itemView)
    {
        super(itemView);
        title = (TextView) itemView.findViewById(R.id.blog_desc);

        username = (TextView) itemView.findViewById(R.id.blog_user_name);
        viewno = (TextView) itemView.findViewById(R.id.blog_date);
       likeno = (TextView) itemView.findViewById(R.id.blog_like_count);
        userdp = (ImageView) itemView.findViewById(R.id.blog_user_image);
        imageview = (ImageView) itemView.findViewById(R.id.blog_image);
        comments = (ImageView) itemView.findViewById(R.id.blog_comment_icon);



    }

        popup.show();
    }




}



public void  filterList(ArrayList<Blog> newList)
{
    list=newList;
    notifyDataSetChanged();
}

}

最后这是我的blog.class:

public class Blog {
String title;
String description;
ArrayList<String> url;
String uid;
int time;
String username;
String image;
String postkey;
String timestamp;
int views;

public int getViews()
{
    return views;
}

public void setViews(int views)
{
    this.views = views;
}

public String getTimestamp()
{
    return timestamp;
}

public void setTimestamp(String timestamp)
{
    this.timestamp = timestamp;
}
public int getTime()
{
    return time;
}

public void setTime(int time)
{
    this.time = time;
}


public String getTitle()
{
    return title;
}

public String getUid()
{
    return uid;
}

public String getPostkey()
{
    return postkey;
}

public void setPostkey(String postkey)
{
    this.postkey = postkey;
}

public String getImage()
{
    return image;
}

public void setImage(String image)
{
    this.image = image;
}

public void setUid(String uid)
{
    this.uid = uid;
}

public String getUsername()
{
    return username;
}

public void setUsername(String username)
{
    this.username = username;
}

public void setTitle(String title)
{
    this.title = title;
}

public String getDescription()
{
    return description;
}

public void setDescription(String description)
{
    this.description = description;
}

public ArrayList<String> getUrl()
{
    return url;
}

public void setUrl(ArrayList<String> url)
{
    this.url = url;
}
}

1 个答案:

答案 0 :(得分:1)

我希望这对你有用。

使用以下代码。

       Picasso.with(context).load(list.get(position).getUrl()).into(holder.imageview);
       Log.e("IMGGPOS", list.get(i).getUrl());

这是

的内容
 for(Blog model : list) {
        imageUrls = new ArrayList<>();;
        imageUrls.addAll(model.getUrl());
        Log.v("IMURLSSS", String.valueOf(imageUrls));
    }
    for(int i=0; i<imageUrls.size(); i++)
    {
        Picasso.with(context).load(imageUrls.get(i)).into(holder.imageview);
        Log.v("IMGGPOS", imageUrls.get(i));
    }