gpt4 book ai didi

java - 将列表信息传递给新 Activity

转载 作者:行者123 更新时间:2023-12-01 08:59:49 26 4
gpt4 key购买 nike

我正在制作一个教程,其中我创建了一个 RecyclerView 屏幕,其中包含带有 optional 的卡片。我希望其中一个 optional 能够将用户带到一个新的 activity,其中包含有关他们选择的卡的更多信息和选项。我的问题是,当我尝试将该特定卡片的特征传输到下一个 SlideViewActivity.java activity 时,我无法成功执行此操作。我尝试将列表转换为数组,然后发送该列表,但我不断获得null值(这可能是由于我所知道的语法所致)。

任何澄清和指导将不胜感激,如果您还需要任何其他代码,请告诉我。

public class Adapter extends RecyclerView.Adapter<Adapter.MyViewHolder> {
private Context mContext;
private List<Properties> dogList;

public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView title, count;
public ImageView thumbnail, overflow;

public MyViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.title);
count = (TextView) view.findViewById(R.id.count);
thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
overflow = (ImageView) view.findViewById(R.id.overflow);
}
}

public Adapter(Context mContext, List<Properties> dogList) {
this.mContext = mContext;
this.dogList = dogList;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card, parent, false);
return new MyViewHolder(itemView);
}

@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
Properties dog = dogList.get(position);
holder.title.setText(dog.getName());
// loading dog cover using Glide library
Glide.with(mContext).load(dog.getThumbnail()).into(holder.thumbnail);
holder.overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPopupMenu(holder.overflow);
}
});
}

/**
* Showing popup menu when tapping on icon
*/
private void showPopupMenu(View view) {
// inflate menu
PopupMenu popup = new PopupMenu(mContext, view);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.menu, popup.getMenu());
popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
popup.show();
}

/**
* Click listener for popup menu items
*/
class MyMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {

public MyMenuItemClickListener() {
}

@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_add_favourite:
Toast.makeText(mContext, "Add to favourite", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_more_info:
Intent slideStart = new Intent(mContext, SlideViewActivity.class);
String[] dogArray = new String[dogList.size()];
slideStart.putExtra("List", dogArray);
Log.e("putting extra", String.valueOf(dogArray[0]));
//TODO:MAKE NAME TRANSFERS WORK
mContext.startActivity(slideStart);
return true;
default:
}
return false;
}
}

添加Properties.java:

public class Properties {
private String name;
private String info;
private int thumbnail;

public Properties() {
}

public Properties(String name, String info, int thumbnail) {
this.name = name;
this.info = info;
this.thumbnail = thumbnail;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getInfo() {
return info;
}

public void getInfo(String info) {
this.info = info;
}

public int getThumbnail() {
return thumbnail;
}

public void setThumbnail(int thumbnail) {
this.thumbnail = thumbnail;
}
}

最佳答案

您可以通过ArrayList<T> ,如果TSerializable .

例如:

ArrayList<String> list = new ArrayList<String>();
intent.putExtra("list", list);

使用getSerializableExtra提取数据

关于java - 将列表信息传递给新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41772344/

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