无法在新活动中打开图像



需要帮助。这可能很奇怪。

第一个活动具有列表视图(如懒惰适配器),一旦我单击列表,它就会打开一个带有描述、标题和图像的新活动。但是我无法显示图像。不知道如何发送...

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);  }

我的第二个活动

 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(整数)传递给您的意图。当您收到该意图时,您可以使用getIntExtra提取它,这将为您提供R.id.list_image的值。然后,您可以在ImageView上调用setImageResource来设置图像。

传入

整数时调用getStringExtra将导致空字符串。

最新更新