AGridView
にはBaseAdapter
、その子に値を設定する責任がある派生クラスがあります。それは正常に動作します。
GridView
スッキリしたら何とかしたいです。つまり、「addOnRefreshListner()」というメソッドがあればいいのにと思います。
API レベル 8 (Froyo) まで対応する必要があります。
カスタムアダプタでBaseAdapter.notifyDataSetChanged()をオーバーライドするとどうなりますか?
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
// A change has happened and caused the GridView to refresh
}
notifyDataSetChanged()
addOnRefreshListener()がない場合の解決策です。
API11以降のを実装してみてくださいView.OnLayoutChangeListener()
。
View myView = findViewById(R.id.my_view);
myView.addOnLayoutChangedListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
// Do what you need to do with the height/width since they are now set
}
});