プログラミングを初めて1ヶ月の初心者です。
Assetsから画像をTry Catchで読み込んでいるのですが、画像が約10枚になった為、コードが長くなり、見にくい状態です。
見やすく記述できる方法はないでしょうか。
よろしくお願いします。
Java
1 ImageView imageView1 = findViewById(R.id.image); 2 3 try (InputStream istream = getResources().getAssets().open("images_activity/rugby.jpg")) { 4 Bitmap bitmap = BitmapFactory.decodeStream(istream); 5 imageView1.setImageBitmap(bitmap); 6 } catch (IOException e) { 7 e.printStackTrace(); 8 } 9 10 ImageView imageView2 = findViewById(R.id.image1); 11 12 try(InputStream istream = getResources().getAssets().open("images_activity/post_horse.jpg")){ 13 Bitmap bitmap = BitmapFactory.decodeStream(istream); 14 imageView2.setImageBitmap(bitmap); 15 }catch (IOException e){ 16 e.printStackTrace(); 17 } 18 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/05 11:21