2012-01-01 17 views
2

私は、ユーザーが数字を入力するEditTextボックスと、いくつかの計算の結果を表示する3つのTextViewを持っています。結果として「2」を表示する代わりに、結果に基づいて特定の画像を表示したいと考えています。すなわち「1」= PIC1「2」= PIC2 ....Androidは計算に基づいて画像を表示します

+0

もっと具体的になりますか?あなたは本当に何をしたいですか?カバーしたいケースについて完全な説明をしていただけますか? –

+0

私は、ユーザーが数字を入力するEditTextボックスと、いくつかの計算の結果を表示する3つのTextViewを持っています。結果として「2」を表示する代わりに、結果に基づいて特定の画像を表示したいと考えています。すなわち "1" = pic1 "2" = pic2 .... – user992244

答えて

1

あなたは計算の結果に基づいて/ SDカードから画像をロードする必要がある場合、これはそれを行うための一つの方法です:

int calculationsResult = ... //do your calculations here
String fileName = "/sdcard/path_to_your_pictures/pic" + calculationsResult + ".jpg";
Bitmap image = BitmapFactory.decodeFile(fileName);
ImageView resultImageHolder = findViewById(R.id.result_holder_id);
resultimageHolder.setImageBitmap(image);

希望すると便利です。

0

すべての結果が整数であると仮定すると、Todorが示唆するように(各画像にあなたが使用できる予測可能なタイトルを与えることによって)行うことができます。しかし、適切なファイル名を取得する別の方法は、単純にHashMapを使用して、結果を表示する画像を記述することです。

Map<String, Integer> hm = new HashMap<String, Integer>(); 

// Put elements to the map 
hm.put(new Integer(2), "number_two.png"); 
hm.put(new Integer(20), "the_number_is_twenty.png"); 
hm.put(new Integer(42), "douglas_adams.png"); 

And when you have done your calculation, you look up in the HashMap to find the filename. 
Integer result = 3+1-2; // Your calculation here 

String filename = "dummy.png"; // When all else fails 
if (hm.containsKey(result)) 
{ 
     filename=(String)hm.get(result); 
}