所以,我加入了新的功能,我的尋寶應用程序,它基本上是顯示的線索圖片的能力。通過點擊線索的文字,我去一個ImageView的活動顯示圖片依賴於線索。問題是,我不知道如何使這項工作。我試着做一個地圖/ 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);
,然後填充與圖片...
imgClue.setImageResource(map.get("goebel"));
點擊文本線索有這樣的代碼:
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來設置根據位置在屏幕上顯示的文字。我希望我可以在Case語句中添加另一行來指出要顯示的圖片。
所以我的問題是,我要對這個錯誤的方式或者是我的代碼只是完全錯了嗎?
的代碼將無法編譯,因爲它只是不喜歡我的MAP報表週期。
感謝, Hendo
'cluePic.putExtra( 「MyImageKey」,map.get( 「格貝爾」));'是不是「goebel」圖像的關鍵?我想我不明白你指的是什麼「MyImageKey」。 –
非常感謝您的幫助和回覆。 :-) –
@DaveHenderson這行有兩個鍵。你是對的''「goebel」是你地圖的關鍵。然後,您將地圖中的值放入「Intent」中,並使用另一個鍵將其發送到下一個活動:-) – Blundell