[英]How do I pass a downloaded image from one activity to the next?
我想将用户单击的下载图像从活动中移至下一个。 我相信这应该在我的lambda onItemClickListenerClass中完成。
我的自定义适配器类的代码在这里:
@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;
}
这是我的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;
}
我已将所有字符串数据捆绑到一个附加文件中并通过意图传递,并且我正在考虑在此上下文中通过将图像转换为附加文件并通过该意图传递来做相同的事情,但是我目前不知道如何实现这一点。
谁能帮助我解决这个问题? 我目前正在做Udacity Android Programmer的最终项目,所以我对android编程还是很陌生。
将Url作为字符串额外传递给第二活动。
在第一个活动/自定义适配器中:
String url = "http://image-url";
Intent intent = new Intent (getActivity().this, 2ndActivity.class);
intent.putExtra("image-url", url);
getActivity().startIntent(intent);
在第二活动中:
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.