我正在使用改造1.9从rest api获取数据以显示在recyclerview中。到目前为止,我正在提供有关用户的所有必要信息。现在我还想在该recyclerview上显示用户的图像。现在,对于用户信息,我有一个API。比如“https://sample.app.com/api/user”。在这个api我没有任何图像字段。收集用户图像我有另一个api,如“https://sample.app.com/api/profileimage/”+ mail.I我试图使用'com.squareup.picasso:picasso:2.5.2'添加图像。但是在运行程序之后,我在recyclerview上看不到任何东西。
这是我的User模型类。我想提一下在json文件中没有提出任何impage。
用户api
[
{
"_id": "588797978",
"dn": "CNdfgdfgdfg",
"sn": "Das",
"title": "title",
"givenName": "Tom",
"whenChanged": "20170623093215.0Z",
"company": "Company limited",
"name": "Soutrik Das",
"mail": "mail@com.de",
"mobile": "+123456",
"updated_at": "2016-12-09T13:37:55.721Z"
},
...
]
我的模型类是
public class ColleagueModel {
public String _id,
dn,
givenName,
whenChanged,
name,
mail,
updatedAt,
sn,
title,
department,
company,
mobile;
..............
}
我给了一部分adpater课程
@Override
public void onBindViewHolder(ColleagueHolder holder, int position) {
final ColleagueModel currentColleague = mColleague.get(position);
Picasso.with(holder.itemView.getContext());
holder.colleagueName.setText(currentColleague.name);
holder.companyName.setText(currentColleague.company);
holder.jobTitle.setText(currentColleague.title);
Picasso.with(holder.itemView.getContext()).load( Constants.HTTP.PHOTO_URL + currentColleague.mail).into(holder.colleaguePicture);
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i=new Intent(context,DetailMyColleague.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(/* here I want to send image*/ )
i.putExtra("name",currentColleague.name);
i.putExtra("title",currentColleague.title);
i.putExtra("company",currentColleague.company);
i.putExtra("mobile",currentColleague.mobile);
i.putExtra("mail",currentColleague.mail);
i.putExtra("department",currentColleague.department);
context.startActivity(i);
}
});
基本网址
public class Constants {
public static final class HTTP {
public static final String BASE_URL = "https://sample.app.com";
public static final String PHOTO_URL = BASE_URL + "/api/profileimage/";
}
public static final class DATABASE{
}
}
详细活动的一部分
Intent intent = getIntent();
//RECEIVE DATA
name = intent.getExtras().getString("name");
int profileImage = intent.getIntExtra("image", 0);
String title = intent.getExtras().getString("title");
String company = intent.getExtras().getString("company");
mobile = intent.getExtras().getString("mobile");
String mail = intent.getExtras().getString("mail");
String dept = intent.getExtras().getString("department");
//BIND DATA
_profilePic.setImageResource(profileImage);
_profileName.setText(name);
_colleagueName.setText(name);
_mobile.setText(mobile);
_mobile.setOnClickListener(this);
_email.setText(mail);
_email.setOnClickListener(this);
_company.setText(company);
_department.setText(dept);
_jobRole.setText(title);
Api服务
public interface ColleagueApiService {
@GET("/api/users")
void getColleague(Callback<String> flowers);
}
持有人类
@Override
public int getItemCount() {
return mColleague.size();
}
public class ColleagueHolder extends RecyclerView.ViewHolder{
public CardView cardView;
public ImageView colleaguePicture;
public TextView colleagueName;
public TextView companyName;
public TextView jobTitle;
public ColleagueHolder(View itemView) {
super(itemView);
colleaguePicture= itemView.findViewById(R.id.colleague_picture);
colleagueName= itemView.findViewById(R.id.colleague_name);
companyName= itemView.findViewById(R.id.company_name);
jobTitle= itemView.findViewById(R.id.job_title);
cardView= itemView.findViewById(R.id.cardview_user);
}
}
如何使用毕加索在recyclerview中添加图像。
Log Cat
08-20 11:57:03.798 1581-2750/? I/ActivityManager: START u0 {cmp=demo.app.com.bluapp_client_and/.activity.myColleague.MyColleaguesPage} from uid 10164 on display 0
08-20 11:57:03.869 29300-29304/demo.app.com.bluapp_client_and I/art: Do partial code cache collection, code=54KB, data=55KB
08-20 11:57:03.871 29300-29304/demo.app.com.bluapp_client_and I/art: After code cache collection, code=45KB, data=50KB
08-20 11:57:03.871 29300-29304/demo.app.com.bluapp_client_and I/art: Increasing code cache capacity to 256KB
08-20 11:57:03.882 29300-29332/demo.app.com.bluapp_client_and D/EGL_emulation: eglMakeCurrent: 0xa4c164a0: ver 2 0 (tinfo 0xa49536c0)
08-20 11:57:03.970 29300-29300/demo.app.com.bluapp_client_and D/Controller: Error :: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $
08-20 11:57:03.970 1581-1601/? I/ActivityManager: Displayed demo.app.com.bluapp_client_and/.activity.myColleague.MyColleaguesPage: +168ms
08-20 11:57:04.355 1581-1797/? I/WindowManager: Destroying surface Surface(name=demo.app.com.bluapp_client_and/demo.app.com.bluapp_client_and.activity.main.MainOptionPage) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.AppWindowToken.notifyAppStopped:389 com.android.server.wm
答案 0 :(得分:0)
将图片网址传递给详细信息页面
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i=new Intent(context,DetailMyColleague.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("IMAGE_URL",Constants.HTTP.PHOTO_URL + currentColleague.mail);
i.putExtra("name",currentColleague.name);
i.putExtra("title",currentColleague.title);
i.putExtra("company",currentColleague.company);
i.putExtra("mobile",currentColleague.mobile);
i.putExtra("mail",currentColleague.mail);
i.putExtra("department",currentColleague.department);
context.startActivity(i);
}
});
获取图片
Intent intent = getIntent();
//RECEIVE DATA
name = intent.getExtras().getString("name");
String profileImage = intent.getExtras().getString("IMAGE_URL");
String title = intent.getExtras().getString("title");
String company = intent.getExtras().getString("company");
mobile = intent.getExtras().getString("mobile");
String mail = intent.getExtras().getString("mail");
String dept = intent.getExtras().getString("department");
//BIND DATA
Picasso.with(this).load(profileImage).into(_profilePic);
// _profilePic.setImageResource(profileImage);
_profileName.setText(name);
_colleagueName.setText(name);
_mobile.setText(mobile);
_mobile.setOnClickListener(this);
_email.setText(mail);
_email.setOnClickListener(this);
_company.setText(company);
_department.setText(dept);
_jobRole.setText(title);