[英]How do I pass a downloaded image from one activity to the next?
I would like to take a downloaded image the user clicked on from on activity to the next. 我想将用户单击的下载图像从活动中移至下一个。 I believe this should be done in my lambda onItemClickListenerClass.
我相信这应该在我的lambda onItemClickListenerClass中完成。
My code for my custom adapter class is here: 我的自定义适配器类的代码在这里:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Movie movie = getItem(position);
if ( movie == null) return null;
ImageView imageView;
/**
* if convertView is empty, set it equal to ImageView
*/
if (convertView == null) {
imageView = new ImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(width, height));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
} else {
imageView = (ImageView) convertView;
}
Uri coverUrl = movie.getMovieCover();
Picasso.with(context)
.load(coverUrl)
.into(imageView);
// Log.e(LOG_TAG, "URL " + url);
return imageView;
}
and this is code from my Object constructor class 这是我的Object构造函数类中的代码
public Uri getMovieCover(){
final String BASE = "http://image.tmdb.org/t/p/w185";
Uri builtUri = Uri.parse(BASE).buildUpon()
.appendEncodedPath(poster_path)
.build();
return builtUri;
}
I have bundled all my string data into an extra and passed it through an intent, and I was thinking of doing the same thing in this context by converting the image into an extra and pass it through the intent, but I currently do not know how to implement that. 我已将所有字符串数据捆绑到一个附加文件中并通过意图传递,并且我正在考虑在此上下文中通过将图像转换为附加文件并通过该意图传递来做相同的事情,但是我目前不知道如何实现这一点。
Can anyone help me with this problem? 谁能帮助我解决这个问题? I am currently doing the Udacity Android Programmer final project so I still am fairly new to android programming.
我目前正在做Udacity Android Programmer的最终项目,所以我对android编程还是很陌生。
Pass the Url as String extra to 2nd Activity. 将Url作为字符串额外传递给第二活动。
In 1st Activity/Custom Adapter : 在第一个活动/自定义适配器中:
String url = "http://image-url";
Intent intent = new Intent (getActivity().this, 2ndActivity.class);
intent.putExtra("image-url", url);
getActivity().startIntent(intent);
In 2nd Activity : 在第二活动中:
String url;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntents();
url = i.getExtra("image-url");
Uri coverUrl = new Uri(url);
if (url.Length() > 0) {
imageView = new ImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(width, height));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
Picasso.with(context)
.load(coverUrl)
.into(imageView);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.