需要帮助。这可能很奇怪。
第一个活动有listview(比如lazyadapter),点击列表后,它会打开一个包含描述,标题和图片的新活动。但是我无法显示图像。不知道如何发送它......
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);
答案 0 :(得分:0)
int thumb_image = in.getIntExtra(KEY_THUMB_URL);
thumb.setImageResource(thumb_image);
您正在将资源ID(整数)传递给您的意图。当您收到该意图时,可以使用getIntExtra
对其进行提取,这将为您提供R.id.list_image
的值。然后,您可以在ImageView上调用setImageResource
来设置图像。
传入整数时调用getStringExtra
将导致空字符串。