スレッドでコードの一部を実行する必要があります。しかし、私はrun()
関数から変数へのアクセスに問題があります。変数(関数引数も)はfinalとして定義する必要がありますが、私はこれを行うとrun()
関数内で値を変更することはできません。例えば、今の変数iv
はrun()
メソッドではアクセスできません。クラス関数内でスレッドを実行中
この問題を解決する方法はありますか?あなたがここに行うために必要なもの
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
convertView = getLayoutInflater().inflate(R.layout.gallery_gridsq, parent, false);
ImageView iv = (ImageView) convertView.findViewById(R.id.icon);
final File file = new File(Uri.parse(getItem(position).toString()).getPath());
Runnable runnable = new Runnable() {
@Override
public void run() {
Bitmap bmp = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeStream(new FileInputStream(file), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
options.inJustDecodeBounds = false;
options.inSampleSize = 2;
try {
bmp = BitmapFactory.decodeStream(new FileInputStream(file), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
iv.setImageBitmap(bmp);
}
};
new Thread(runnable).start();
return convertView;
}
あなたは 'iv'変数を再割り当てしていません...' final'にすることができます –