我正在尝试使用 listview 项将图像从一个活动传递到另一个活动,但我收到此错误行
方法 setImageResource(int)
是图像视图类型不适用于参数(字符串),并且在这一点上: -
lblImage.setImageResource(图像);
我现在不知道需要写什么来消除此错误请有人支持我并编写适合此行的确切代码,在这里我还放置一些代码供您参考:
SingleMenuItem(Activity to fetch Image with some text data)::
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_list_item);
// getting intent data
Intent in = getIntent();
// Get XML values from previous intent
String title = in.getStringExtra(KEY_TITLE);
String artist = in.getStringExtra(KEY_ARTIST);
String duration = in.getStringExtra(KEY_DURATION);
String Image = in.getStringExtra(KEY_THUMB_URL);
//Bitmap bitmap =(Bitmap) in.getParcelableExtra(KEY_THUMB_URL);
// ImageView image = (ImageView)findViewById(R.id.thumb_url);
// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.name_label);
TextView lblCost = (TextView) findViewById(R.id.email_label);
TextView lblDesc = (TextView) findViewById(R.id.mobile_label);
ImageView lblImage = (ImageView) findViewById(R.id.image_label);
//image.setImageBitmap(bitmap);
lblName.setText(title);
lblCost.setText(artist);
lblDesc.setText(duration);
lblImage.setImageResource(Image); //Getting Error at this line only
//the method setImageResource(int) is the type Image View is not
// applicable for the argument(string)
}
}
ActivityCode (to pass image and text data)
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String title = ((TextView) view.findViewById
(R.id.title)).getText().toString();
String artist = ((TextView) view.findViewById(
R.id.artist)).getText().toString();
String duration = ((TextView) view.findViewById
(R.id.duration)).getText().toString();
// byte[] array = null;
// Bitmap thumb_url = BitmapFactory.decodeByteArray
(array, 0, array.length);
String Image=((ImageView)view.findViewById
(R.id.list_image)).getImageMatrix().toString();
// Starting new intent
Intent in = new Intent
(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_ARTIST, artist);
in.putExtra(KEY_DURATION, duration);
in.putExtra(KEY_THUMB_URL, Image);
//in.putExtra(KEY_THUMB_URL, thumb_url);
startActivity(in);
}