アプリケーションのボタンを押すと、画像を表示する必要があります。
私が試しているのは:
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageDrawable(R.drawable.loading);
しかし、それはエラーを示しています。
誰でも私を助けることができますか?ありがとう。
アプリケーションのボタンを押すと、画像を表示する必要があります。
私が試しているのは:
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageDrawable(R.drawable.loading);
しかし、それはエラーを示しています。
誰でも私を助けることができますか?ありがとう。
import package_name.R.drawable;
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageResource(drawable.loading);
また
最初から画像を設定し、非表示に設定し、表示したいときに表示プロパティを変更するだけです。
将来の訪問者のために:
いつかsetImageDrawable(Drawable)
メソッドは次のようなエラーを表示します:
ImageView 型のメソッド setImageDrawable(Drawable) は、引数 (int) には適用されません。
次のコードを試すことができます:
ImageView imageView = (ImageView) findViewById(R.id.myImageView);
Drawable image = getResources().getDrawable(R.drawable.your_image);
imageView.setImageDrawable(image);
--------- またはこれを試すことができます ------------------
imageView.setImageDrawable(ContextCompat.getDrawable(YourActivity.this, R.drawable.your_image));
それがあなたのために働くことを願っています。