私はアンドロイドでトーストを使用してメッセージを何度も表示しましたが、問題はありませんでした。これには、メソッドの内外に配置することが含まれます。ただし、今回は何らかの理由でコンパイラが動作を許可しません。以下に示すこのメソッド内にトーストを配置できないのはなぜですか?
このコードでは、「ThumbnailsActivity.class」と「this」の両方のタイプのコンテキストを試しました。
メソッド decodeSampleBitmapFromResource は、Activity を拡張する Android クラス ThumbnailsActivity.java 内にあります。ここでは何も珍しいことはありません。
public static Bitmap decodeSampledBitmapFromResource(String fileName, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(fileName, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(fileName, options);
// both of the toasts shown here have compile errors
Toast.makeText(ThumbnailsActivity.class, "TEST",Toast.LENGTH_LONG).show();
Toast.makeText(this, "TEST",Toast.LENGTH_LONG).show();
}//end decodeSampledBitmapfromresource method