ImageView に onImageChangedListener() はありますか?
画像が ImageView から変更されたときにイベントが必要です。
ImageView に onImageChangedListener() はありますか?
画像が ImageView から変更されたときにイベントが必要です。
Androidにはデフォルトのリスナーはありませんが、imagechange listinerを作成できます。クラスをコピーし、ImageViewを使用する代わりにMyImageViewを使用します。
public class MyImageView extends ImageView {
private OnImageChangeListiner onImageChangeListiner;
public MyImageView(Context context) {
super(context);
}
public MyImageView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
public void setImageChangeListiner(
OnImageChangeListiner onImageChangeListiner) {
this.onImageChangeListiner = onImageChangeListiner;
}
@Override
public void setBackgroundResource(int resid) {
super.setBackgroundResource(resid);
if (onImageChangeListiner != null)
onImageChangeListiner.imageChangedinView(this);
}
@Override
public void setBackgroundDrawable(Drawable background) {
super.setBackgroundDrawable(background);
if (onImageChangeListiner != null)
onImageChangeListiner.imageChangedinView(this);
}
public static interface OnImageChangeListiner {
public void imageChangedinView(ImageView mImageView);
}
}
grepcodeのimageviewコードを確認してください。いつ変更または再描画されるかわかりません。これは、setImageDrawable()を設定すると、imageviewが無効になるためです。このとき、ondrawが呼び出されるまで、画像は正しく変更されません。
とにかく、なぜonimagechangedlistenerを知りたいのですか?