我正在尝试将imageview和country_name从一个活动转发到另一个活动。
我已经在网上搜索了,但找不到任何东西。
recycleviewholders
public TextView countryName;
public ImageView countryPhoto;
public RecyclerViewHolders(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
countryName = (TextView)itemView.findViewById(R.id.country_name);
countryPhoto = (ImageView)itemView.findViewById(R.id.country_photo);
}
项目对象
public class ItemObject {
private String name;
private int photo;
public ItemObject(String name, int photo) {
this.name = name;
this.photo = photo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPhoto() {
return photo;
}
public void setPhoto(int photo) {
this.photo = photo;
}
}
希望有人能帮助我一点。
更新:我在主页上显示它,当我按下图像时,我希望它在
activity_main_tours
中显示该图像和文本。private List<ItemObject> getAllItemList() {
List<ItemObject> allItems = new ArrayList<ItemObject>();
allItems.add(new ItemObject("Half day fishing", R.drawable.newyork));
allItems.add(new ItemObject("Private Charter", R.drawable.canada));
allItems.add(new ItemObject("Full day fishing", R.drawable.germany));
return allItems;
}
这是显示链接的代码:
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "Clicked Country Position = " + getPosition(), Toast.LENGTH_SHORT).show();
Intent intent=new Intent(v.getContext(),MainTours.class);
v.getContext().startActivity(intent);
}
更新:我找到了这段代码,我可以使用这个代码吗?
public void openEvent(View v)
{
intent= new Intent(EventActivity.this,DetailActivity.class);
switch (v.getId()) {
case R.id.event1:
intent.putExtra("event_name", R.string.name);
intent.putExtra("img", R.drawable.image);
intent.putExtra("desc", R.string.desc_1);
最佳答案
发送数据(发送者活动)
intent = new Intent(getActivity(), CheckinActivity.class);
intent.putExtra("mealID", meal.Meald);
startActivity(intent);
获取数据(第二活动)
int mealId;
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if(bundle != null){
mealId = bundle.getInt("mealID");
}
关于android - 将imageview和country_name从一项 Activity 转发到secondactivity,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59254195/