我想在回收站视图O单击但把我的名字和图像数据IM有点糊涂了,我应该用paraceble或简单的捆绑机制如何我发送和recived它如何发送使用RecyclerView的onclick方法里面包
public class FamousPeople
{
private static final String FAMOUS_NAME = "famous name";
private static final String FAMOUS_PHOTO="photo";
private String name;
private int photo;
private String details;
FamousPeople(String name, int photo) {
this.name = name;
this.photo = photo;
}
public FamousPeople(){
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public int getPhoto() {
return photo;
}
public void setPhoto(int photo) {
this.photo = photo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
BiographyViewHolder类中,我要通过我的图片和文字资料
class BiographyViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
public TextView textView;
public ImageView imageView;
List<FamousPeople> famousPeoples=GetData.getListdata();
public BiographyViewHolder(View itemView)
{
super(itemView);
itemView.setOnClickListener(this);
textView= (TextView) itemView.findViewById(R.id.country_name);
imageView= (ImageView) itemView.findViewById(R.id.country_photo);
}
@Override
public void onClick(View view) {
Intent intent=new Intent();
Bundle bundle=new Bundle();
intent.putExtras(bundle);
view.getContext().startActivity(intent);
}
}
的GetData类从该类获取数据
public class GetData {
public static List<FamousPeople> getListdata() {
List<FamousPeople> famousPeoples = new ArrayList<>();
famousPeoples.add(new FamousPeople("rahul", R.drawable.amitabh));
famousPeoples.add(new FamousPeople("sumit", R.drawable.cvraman));
famousPeoples.add(new FamousPeople("neha", R.drawable.indira));
famousPeoples.add(new FamousPeople("surbhi", R.drawable.kishorkumar));
famousPeoples.add(new FamousPeople("rahul", R.drawable.modi));
famousPeoples.add(new FamousPeople("sumit", R.drawable.mother));
famousPeoples.add(new FamousPeople("neha", R.drawable.nehru))
return famousPeoples;
}
无论是paraceble/serializable还是简单的bundle机制在你的情况下都很好 –
但是序列化在性能上比paraceble慢,我会用xml pull parser来获取数据,所以有点混淆何时使用paraceble和什么时候使用简单的捆绑 – rahul