使用传递的String调用资源

时间:2015-03-07 02:40:07

标签: java android android-intent resources

我正在编写一个Android原生应用程序,该应用程序应向用户显示多个露营车模型的360度全景图。我有选择列表,这导致精确的模型。

我没有为每个活动定义活动,而是尝试将变量传递给panorama-activity来调用所请求的图像。但我说得不对。

这是接收端的代码:

public class Panoviewer extends PLView {



public void onCreate (Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    //this.load(new PLJSONLoader("res://raw/json_spherical"));
    PLSpherical2Panorama panorama = new PLSpherical2Panorama();
    Intent intentExtras = getIntent();
    String pano = getIntent().getExtras().getString("pano");

    Log.d("MSG", pano);
    //gets R.raw.spherical_pano from previous Activity

    panorama.setImage(new PLImage(PLUtils.getBitmap(this, R.raw.spherical_pano), false));
    this.setPanorama(panorama);

}


}

我不想使用直接的“R.raw.spherical_pano”,而是想使用之前活动中的String。只需在“panorama.setImage ...”中进行交换就无法实现。

2 个答案:

答案 0 :(得分:1)

为什么不直接传递R.raw.sherical_pano?由于资源引用是int,您可以像

一样传递它
int pano = getIntent().getExtras().getInt("key");

然后设置为

panorama.setImage(new PLImage(PLUtils.getBitmap(this, pano), false));

答案 1 :(得分:0)

尝试使用:

 int myId = context.getResources().getIdentifier("yourString","raw", context.getPackageName())

然后:

 panorama.setImage(new PLImage(PLUtils.getBitmap(this, myId), false));
相关问题