需要帮助。这可能很奇怪。
第一个 Activity 有 ListView (如 lazyadapter),一旦我单击列表,它就会打开一个带有描述、标题和图像的新 Activity 。但是我无法显示图像。不确定如何发送...
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
String description = ((TextView) view.findViewById(R.id.artist)).getText().toString();
String pdate = ((TextView)view.findViewById(R.id.pdate)).getText().toString();
//ImageView thumb = ((ImageView) view.findViewById(R.id.list_image));
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_PLAYER, title);
in.putExtra(KEY_THUMB_URL, R.id.list_image);
in.putExtra(KEY_TRANSACTION, description);
in.putExtra(KEY_PUBDATE, pdate);
startActivity(in); }
我的第二个 Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent in = getIntent();
String title = in.getStringExtra(KEY_PLAYER);
String description = in.getStringExtra(KEY_TEXT);
String pdate = in.getStringExtra(KEY_PUBDATE);
String thumb_image = in.getStringExtra(KEY_THUMB_URL);
TextView lblName = (TextView) findViewById(R.id.name_label);
TextView lblDesc = (TextView) findViewById(R.id.description_label);
TextView lblPdate = (TextView) findViewById(R.id.pubdate_label);
ImageView thumb = (ImageView) findViewById(R.id.thumb_label);
lblName.setText(title);
thumb.setImageURI(Uri.parse(thumb_image));
lblDesc.setText(description);
lblPdate.setText(pdate);
最佳答案
int thumb_image = in.getIntExtra(KEY_THUMB_URL);
thumb.setImageResource(thumb_image);
您正在将资源 ID(整数)传递给您的 Intent 。当您收到该 Intent 时,您可以使用 getIntExtra
提取它,这将为您提供 R.id.list_image
的值。然后您可以在 ImageView 上调用 setImageResource
来设置图像。
当您传入整数时调用 getStringExtra
将导致空字符串。
关于android - 无法在新 Activity 中打开图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10432357/