我有以下代码。我在对象 o
中有数据。 o
中有三组值(描述、名称、图片 url)。我需要将这些数据初始化为字符串并使用 intent 将其传递给其他 Activity 。如何获取对象中的每个值。每个列表项都有一个图像、项目名称和项目描述。
fp_list.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView parentView, View v, int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "pos"+position, Toast.LENGTH_LONG).show();
Object o = parentView.getItemAtPosition(position);
Intent i = new Intent(FeaturedProductsActivity.this, ShowProduct.class);
}
}
最佳答案
更好的办法是让你自定义对象 Parcelable
另一个选项是将这些值一一传递为:
Intent i=new Intent(FeaturedProductsActivity.this,ShowProduct.class);
i.putString("desc", o.getDescription());
i.putString("name", o.getName());
// rest of your values
在 ShowProduct
Activity 中获取这些值作为:
Intent in = this.getIntent();
String name = in.getStringExtra("name");
String desc = in.getStringExtra("desc");
//rest of you values
关于android - 如何将数据从 ListView 中的选定项目传递到另一个 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8352467/