gpt4 book ai didi

android - 如何将详细信息从 Recycler View 传递到另一个 Activity ?

转载 作者:行者123 更新时间:2023-11-30 01:48:43 26 4
gpt4 key购买 nike

public class RVAdapter extends
RecyclerView.Adapter<RVAdapter.PersonViewHolder> { public
List<Person> persons= Collections.emptyList(); // private Context
mContext; private LayoutInflater inflater;



ImageLoader mImageLoader = AppController.getInstance().getImageLoader();

private static Context context;


public RVAdapter(Context context, List<Person> persons) {
this.persons = persons;
this.context = context;
inflater = LayoutInflater.from(context);
}

@Override
public PersonViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview,
parent, false);
PersonViewHolder pvh = new PersonViewHolder(v);


return pvh;
}

@Override
public void onBindViewHolder(PersonViewHolder holder, int postions) {

Person person = persons.get(postions);
holder.phoneName.setText(person.getKitchen_accesries());
holder.phonePrice.setText(person.getKitchen_price());
holder.itemView.setTag(person);

if (mImageLoader == null)
mImageLoader = AppController.getInstance().getImageLoader();
holder.thumbnail.setImageUrl(person.getThumbnail(), mImageLoader);


}


@Override
public int getItemCount() {
if (persons != null) {
return persons.size();
}
return 0;
}


@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}

public static class PersonViewHolder extends RecyclerView .ViewHolder
implements View
.OnClickListener {
CardView cv;
TextView phoneName;
TextView phonePrice;
public List<Person> persons;


NetworkImageView thumbnail;

PersonViewHolder(View itemView) {
super(itemView);

cv = (CardView) itemView.findViewById(R.id.card_view);
phoneName = (TextView) itemView.findViewById(R.id.phone_name);
phonePrice = (TextView) itemView.findViewById(R.id.phone_price);
thumbnail = (NetworkImageView) itemView.findViewById(R.id.thumbnail);
itemView.setOnClickListener(this); //
}

@Override
public void onClick(View view ) {



Intent intent = new Intent(context,ViewActivity.class);

context.startActivity(intent);

}


}


}

一旦我触摸 recyclerview 上的项目,它就会转到 Viewactivity 类,但我无法将列表中的详细信息传递给 detailsactivity 类。我想使用 put extra 将我的 Web 服务中的三个详细信息传递到 View Activity 。但是在 Onclick 方法中我没有从列表中获得项目的确切位置。

最佳答案

在你的onclick中添加以下内容

Person person =(Person)view.getTag();
String strUrl= person.getThumbnail();
String product1=person.getKitchen_accesries();
intent.putExtra("Your string key",strUrl);
intent.putExtra("Your string key",product1);
intent.putExtra("Your string key",product1);
context.startActivity(intent);

然后访问您的详细信息 Activity 中的所有内容

phone=(TextView)findViewById(R.id.textView_phone);
price=(TextView)findViewById(R.id.textView_price);
product=(ImageView)findViewById(R.id.imageView);

Bundle bundle = getIntent().getExtras();

String url = bundle.getString("Image");

phone.setText(bundle.getString("Your string key"));
price.setText(bundle.getString("Your string key"));

Picasso.with(getApplicationContext()).load(url).into(product);


关于android - 如何将详细信息从 Recycler View 传递到另一个 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33341533/

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