gpt4 book ai didi

android - 如果我无法获得上下文,我怎么能像 picasso 一样使用?

转载 作者:行者123 更新时间:2023-11-29 14:30:10 25 4
gpt4 key购买 nike

我使用 firbase-ui 显示一个 recyclerView ,它扩展了 Activity ,就像这样:

FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<ChatItem, ExpenseHolder>
(ChatItem.class, R.layout.chat_room_list, ExpenseHolder.class, secondRoot) {
@Override
protected void populateViewHolder(ExpenseHolder viewHolder, ChatItem chatItem, int position) {
viewHolder.setValues(chatItem);
}
};
recyclerChat.scrollToPosition(adapter.getItemCount() - 1);//just let the latest data below
//recyclerChat.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));//增加橫線
recyclerChat.setAdapter(adapter);

LinearLayoutManager manager = new LinearLayoutManager(this);
manager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerChat.setLayoutManager(manager);

这是我的 ExpenseHolder ,我发现它必须是静态的,否则会导致崩溃

    public static class ExpenseHolder extends RecyclerView.ViewHolder {
private final TextView textRightMsg;
private final TextView textLeftMsg;
private final TextView rightTime;
private final ImageView rightImage;

public ExpenseHolder(View itemView) {
super(itemView);

textRightMsg = (TextView) itemView.findViewById(R.id.textRight);
textLeftMsg = (TextView) itemView.findViewById(R.id.textLeft);
rightTime = (TextView) itemView.findViewById(R.id.rightTime);
rightImage = (ImageView) itemView.findViewById(R.id.rightImage);
}

public void setValues(ChatItem chatItem) {
String myName = chatItem.getName();
if (myName.equals(userName)) {
textRightMsg.setText(chatItem.getMsg() + "(" + chatItem.getName() + ")");
rightTime.setText(chatItem.getTime());
// I don't know how to get context in this class
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(rightImage);
} else {
textLeftMsg.setText(chatItem.getMsg() + "(" + chatItem.getName() + ")");
}
}
}

当我想使用 Picaso 设置图像时,我发现我无法获取 contex

我尝试设置全局 privat static Context contex; ,它显示 error context is null 。

这是我要显示的资源 enter image description here

如何在静态环境中显示资源为 url 的图像?

最佳答案

试试这个方法..

Picasso.with(rightImage.getContext()).load("http://i.imgur.com/DvpvklR.png").into(rightImage);

关于android - 如果我无法获得上下文,我怎么能像 picasso 一样使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42826767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com