使用Parse.com在适配器中加载毕加索图像

时间:2015-02-01 11:50:01

标签: android parse-platform picasso

我尝试了很多不同的例子并阅读了很多堆栈溢出的答案和问题,但现在我丢失了...这是我正常设置的ArrayAdapter来填充listview

public class ChatAdapter extends ArrayAdapter<ParseObject> {

protected Context mContext;
protected List<ParseObject> mMessages;

public ChatAdapter(Context context, List<ParseObject> messages) {
    super(context, R.layout.chat_item, messages);
    mContext = context;
    mMessages = messages;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder;

    if(convertView == null) {

        convertView = LayoutInflater.from(mContext).inflate(R.layout.chat_item, null);
        holder = new ViewHolder();
        holder.userImageView = (ImageView) convertView.findViewById(R.id.userImage);
        holder.chatImageView = (ParseImageView) convertView.findViewById(R.id.imageView);
        holder.chatText = (TextView) convertView.findViewById(R.id.textLabel);
        holder.usernameLabel = (TextView) convertView.findViewById(R.id.whenLabel);
        holder.whenLabel = (TextView) convertView.findViewById(R.id.usernameLabel);
        convertView.setTag(holder);

    } else {

        holder = (ViewHolder)convertView.getTag();
    }


    ParseObject message = mMessages.get(position);

INSERT ANSWER

    if (message.getParseFile("image") != null) {

        holder.chatImageView.setVisibility(View.VISIBLE);
        String chatImageFile = message.getParseFile("image").getUrl();

        Picasso.with(mContext)
                .load(chatImageFile)
                .into(holder.chatImageView);

    } else {

        holder.chatImageView.setVisibility(View.GONE);
    }

END ANSWER

    holder.userImageView.setImageResource(R.drawable.ic_action_picture);
    //holder.chatImageView.setImageResource(R.drawable.ic_action_picture);
    holder.chatText.setText(message.getString(ParseConstants.KEY_CHAT_TEXT));
    //holder.usernameLabel.setText(message.getParseUser(ParseConstants.KEY_FROM_USER));
    holder.whenLabel.setText(message.getString(ParseConstants.KEY_CREATED_AT));




    return convertView;
}

private static class ViewHolder {

    ImageView userImageView;
    ParseImageView chatImageView;
    TextView chatText;
    TextView usernameLabel;
    TextView whenLabel;

}

}

现在的问题是我不知道如何将picasso图像加载器实现到这里,在哪里放置Picasso加载器以及我如何获得ParseFile chatImageView ...

有人可以让我回到正轨; - )

0 个答案:

没有答案