2013-04-25 24 views
-1

中的數據更改圖像我是android新手,我正在開發一個應用程序,它必須根據android中另一個屏幕發送的數據更改圖像。 這是如何實現的? 有人可以幫助我嗎?如何根據android

+0

你有沒有嘗試過一些東西。請發佈您的代碼。 – 2013-04-25 21:16:15

+0

是否要將數據從一項活動傳遞給另一項?如果是這樣,看看這個問題,看看如何傳遞數據http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android – Elior 2013-04-25 21:23:00

回答

1

您可以使用額外功能將數據從一項活動發送到另一項活動。

關於你的第一個活動電話是這樣的:

Intent intent = new Intent(this, AnotherActivity.class); 
intent.putExtra("SOME_ID", id_you_want_to_send); 
startActivity(intent); 

然後在其他活動可以通過執行讀取該數據如下:

Bundle extras = getIntent().getExtras(); 
int id = -1; 
if (extras != null) { 
    id = extras.getInt("SOME_ID"); 
} 

,那麼你可以設置內的圖像和if-else或您選擇的開關盒並更改圖像視圖內的圖像,則需要以下代碼:

ImageView img = (ImageView)findById(your_image_id); 
img.setImageResource(R.drawable.the_image_you_want_to_set); 

其中image_you_want_to_set位於項目的可繪製文件夾內。

希望能解決你的問題

+0

謝謝marimaf圖像變化你提到的代碼解決了我的問題 – sneha 2013-04-28 02:25:28

+0

很高興我可以提供幫助 – marimaf 2013-04-28 21:10:41