微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我需要发送一个像我发送字符串“标题”的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); 
}

原文地址:https://www.jb51.cc/android/430872.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐