Android 一个简单的图像弹出窗口

Android 一个简单的图像弹出窗口,android,dictionary,hashmap,android-imageview,Android,Dictionary,Hashmap,Android Imageview,因此,我在我的拾荒者狩猎应用程序中添加了一个新功能,基本上就是显示一张图片作为线索的能力。通过点击线索文本,我进入ImageView活动,以显示依赖于该线索的图片。问题是,我不知道该怎么做。我试着做一个Map/HashMap组合 Map<String, Integer> map = new HashMap<String, Integer>(); map.put("info", R.drawable.clue0); map.put("goebel", R.drawable.

因此,我在我的拾荒者狩猎应用程序中添加了一个新功能,基本上就是显示一张图片作为线索的能力。通过点击线索文本,我进入ImageView活动,以显示依赖于该线索的图片。问题是,我不知道该怎么做。我试着做一个Map/HashMap组合

Map<String, Integer> map = new HashMap<String, Integer>();
map.put("info", R.drawable.clue0);
map.put("goebel", R.drawable.clue1);
map.put("church", R.drawable.clue2);
map.put("confed", R.drawable.clue3);
map.put("ban", R.drawable.clue4);
map.put("jr", R.drawable.clue5);
map.put("ohara", R.drawable.clue6);
map.put("db", R.drawable.clue7);
单击文本线索会显示以下代码:

txtClue.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                Intent cluePic = new Intent(FCRun.this, imgClue.class);
                Intent imgClue;
                cluePic.putExtras(imgClue);
            }

        });
ImageView活动代码(到目前为止)如下所示

public class imgClue extends Activity{
public static ImageView iClue;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.imgclue);

}

public static void setImageResource(Integer integer) {

    }}
“我的近距离警报”会传递一个ID来表示显示的位置。我使用Switch(ID)/Case根据位置设置屏幕上显示的文本。我希望我能在案例陈述中再加一行,告诉大家要显示什么样的图片

所以我的问题是,我是不是走错了路,还是我的代码完全错了

代码不会编译,因为它不喜欢MAP语句中的句点

谢谢,
Hendo

由于以下两行代码,代码无法编译:

 Intent imgClue;
 cluePic.putExtras(imgClue);
删除它们并将其替换为

 startActivity(cluePic);

这也是错误的
imgClue.setImageResource(map.get(“goebel”)
您不应该将map(即整数可绘制资源)的结果设置为静态方法。您应该将其传递给意图,例如:

cluePic.putExtra(“MyImageKey”,map.get(“goebel”)

然后在您的活动(imgClue)中
onCreate

 int imageDrawableResource = getIntent().getIntExtra("MyImageKey", 0);

虽然您的代码并不完美,但这是一种完美的方法。:-)


为了使您的代码在以后更易于理解,我建议您进行以下更改:

  • 地图
    更改为
    地图组
  • txtClue
    更改为
    clueTextView
  • Intent cluePic
    更改为
    Intent cluepictureentent
  • imgClue扩展活动
    更改为
    ImageClueActivity扩展活动
  • publicstaticimageview iClue
    中删除static关键字,并将其设为private:
    private ImageView cluemageview

在这行中,“cluePic.putExtra(“MyImageKey”,map.get(“goebel”);”“戈贝尔”不是图像键吗?我想我不明白你所指的“MyImageKey”是什么。谢谢你的帮助和这么快的回复。:-)@这行有两把钥匙。你是正确的
“goebel”
是地图的关键。然后将地图中的值放入
意图中,并使用另一个键将其发送到下一个活动:-)
 int imageDrawableResource = getIntent().getIntExtra("MyImageKey", 0);