我制作了一个应用,我使用weburl
xmlparsing
中的listview
检索来自onItemClick
的数据(带有图像和少量文本字段),我编写了{{1}的代码}和值显示给另一个活动,但我无法将图像从一个活动发送到另一个活动,但是使用listview
项目发送文本数据。
有人可以指导我并编写一些代码,还有一些描述吗?
以下是我的一些代码:
MainActivity Code:
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();
String image=((ImageView)view.findViewById
(R.id.list_image)).getImageMatrix().toString();
//byte[] array=null;
//Bitmap bMap = BitmapFactory.decodeByteArray
// (array, 0, array.length);
// 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);
startActivity(in);
}
});
}
}
SingleMenuItemActivity Code:-
public class SingleMenuItemActivity extends Activity {
// XML node keys
private static final String KEY_TITLE = "title";
private static final String KEY_ARTIST = "artist";
private static final String KEY_DURATION = "duration";
private static final String KEY_THUMB_URL = "thumb_url";
@Override
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);
// 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);
lblName.setText(title);
lblCost.setText(artist);
lblDesc.setText(duration);
//Getting error in below line
//the method setImageResource(int) is the type
//Image View is not applicable for the argument(string)
lblImage.setImageResource(image);//(R.drawable.rihanna);
}
}
答案 0 :(得分:0)
将此图像转换为位图,并使用Intent.putExtra()将其作为包传递给下一个活动。
答案 1 :(得分:0)
您不必通过Bundle
传递图片,而是传递image path as String data
,并且在每个活动中,无论您需要图片,都可以从该图片路径创建图片。
答案 2 :(得分:0)
in.putExtra(KEY_IMAGE, image);
其中image是byte [] ..任何图像都可以转换为bytearray .. 并且在调整时
Bitmap bMap = BitmapFactory.decodeByteArray(array, 0, array.length);
`