android– 如何将图像从一个活动发送到其他活动?

android– 如何将图像从一个活动发送到其他活动?,第1张

概述我需要发送一个像我发送字符串“标题”的imageview,但我不能,我怎样才能将主视图中的imageview(R.drawable.image)发送到第二个活动?谢谢主要活动public void NewActivity(View view){ Intent intent = new Intent(this, SecondActivity.class);

我需要发送一个像我发送字符串“标题”的imagevIEw,但我不能,我怎样才能将主视图中的imagevIEw(R.drawable.image)发送到第二个活动?

谢谢

主要活动

public voID NewActivity(VIEw vIEw){ Intent intent = new Intent(this,SecondActivity.class); intent.putExtra("Title",getString(R.string.Title));    startActivity(intent); } 

第二次活动

@OverrIDe public voID onCreate(Bundle bundle) { super.onCreate(bundle); setContentVIEw(R.layout.pantalla); Bundle extras = getIntent().getExtras(); if (extras == null) { return; } String Title = extras.getString("Title"); TextVIEw textvIEw = (TextVIEw)findVIEwByID(R.ID.titulo); textvIEw.setText(Title); }
最佳答案解决方案1 ​​:(对于不可绘制的资源)

您可以将路径文件名作为字符串发送.就像你的例子中的“标题”一样.

如果您对ImageVIEw使用filepath有问题.
Show Image View from file path?

解决方案2 :(适用于简易和轻便的方式)

发送资源整数值,如:

主要活动

Intent intent = new Intent(this,SecondActivity.class); intent.putExtra("resourseInt",R.drawable.image);    startActivity(intent); 

第二次活动

@OverrIDe public voID onCreate(Bundle bundle) {     super.onCreate(bundle);     setContentVIEw(R.layout.pantalla);     Bundle extras = getIntent().getExtras();     if (extras == null)     {         return;     }     int res = extras.getInt("resourseInt");     ImageVIEw vIEw = (ImageVIEw) findVIEwByID(R.ID.something);     vIEw.setimageResourse(res); }
总结

以上是内存溢出为你收集整理的android – 如何将图像从一个活动发送到其他活动?全部内容,希望文章能够帮你解决android – 如何将图像从一个活动发送到其他活动?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1140265.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存