Это мое решение:
Я подкласс GridView с конструктором (Context, AttributeSet):
(это для меня должно быть сделано в отдельном классе файлов)
и переопределил метод onSizeChanged
MyGrid.java
public class MyGrid extends GridView {
public void MyGrid(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// TODO Auto-generated method stub
// Here I call my custom functions to prepare layout of my custom listview
super.onSizeChanged(w, h, oldw, oldh);
}
}
В классе Activity, чем использовать GridView,
Я переопределил метод onStart
(вызывается после OnCreate и после OnRestart
[когда вы пришли из другого занятия])
MyActivity.java
public class MyActivity extends Activity {
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(...)
...
}
....
protected void onStart() {
// TODO Auto-generated method stub
// call db and create cursor
// 'mygridview' = findbyid MyGrid
// (declared on xml like '<packagepath>'.mygrid
// setadapter with my costom adapeter
// **HERE THE CALLED ONSIZECHANGED**
// I make test proper for my app
// (there is a simple test)
if ('mygridview'.getMeasuredHeight() > 0) {
// I use the same width and height for new and old measures
// because for me that is right
'mygridview'.onSizeChanged(gw.getWidth(), gw.getHeight(),
gw.getWidth(), gw.getHeight());
}
super.onStart();
}
}
При таком подходе я могу изменить размер моей сетки в любое время.
Я надеюсь, что это вам полезно.