如何从一个活动图像发送给其他? [英] how to send image from one activity to other?

查看:105
本文介绍了如何从一个活动图像发送给其他?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要发送的ImageView像我发送字符串称号,但我不能,我怎样才能从mainactivity发送ImageView的(R.drawable.image),以secondactivity?

感谢

主要活动

 公共无效NewActivity(查看视图){
意向意图=新意图(这一点,SecondActivity.class);
intent.putExtra(称号的getString(R.string.title));
startActivity(意向);
}

第二项活动

  @覆盖
公共无效的onCreate(捆绑包)
{super.onCreate(包);
的setContentView(R.layout.pantalla);
捆绑额外= getIntent()getExtras()。
如果(演员== NULL)
{
返回;
}
字符串title = extras.getString(标题);TextView中的TextView =(的TextView)findViewById(R.id.titulo);textview.setText(职称);
}


解决方案

解决方案1:(适用于非绘制资源)

您可以发送路径文件名作为一个字符串。就像在你的例子在标题

如果你有问题文件路径的使用率ImageView的。
在Android的显示图像查看从文件路径?


解决方案2:(适用于绘制容易和放大器;光路)

发送资源整数值,如:

主要活动

 意向意图=新意图(这一点,SecondActivity.class);
intent.putExtra(resourseInt,R.drawable.image);
startActivity(意向);

第二项活动

  @覆盖
公共无效的onCreate(捆绑包)
{    super.onCreate(包);
    的setContentView(R.layout.pantalla);
    捆绑额外= getIntent()getExtras()。
    如果(演员== NULL)
    {
        返回;
    }
    INT解析度= extras.getInt(resourseInt);    ImageView的观点=(ImageView的)findViewById(R.id.something);    view.setImageResourse(RES);
}

I need send a imageview like i send the string "title", but i can't, how can i send a imageview (R.drawable.image) from mainactivity to secondactivity?

THANKS

MAIN ACTIVITY

public void NewActivity(View view){ 
Intent intent = new Intent(this, SecondActivity.class); 
intent.putExtra("title", getString(R.string.title));    
startActivity(intent); 
} 

SECOND ACTIVITY

@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); 
}

解决方案

Solution 1: (for non drawable resources)

You can send the path filename as a string. Just like the "title" in your example.

If you have problem with usage of filepath to ImageView. Show Image View from file path in android?


Solution 2: (for drawable easy & light way)

Send the resource integer value like:

MAIN ACTIVITY

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

SECOND ACTIVITY

@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); 
}

这篇关于如何从一个活动图像发送给其他?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆