This is my decision:
I subclassed the GridView using the constructor (Context, AttributeSet):
(this should be done for me in a separate file class)
and redefined the onSizeChanged method
MyGrid.java public class MyGrid extends GridView { public void MyGrid(Context context, AttributeSet attrs) { super(context, attrs);
In the Activity class, than using a GridView,
I redefined the onStart method
(called after OnCreate and after onRestart [when you came from another activity])
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(); } }
With this approach, I can resize the grid at any time. Hope this helps you.
rfellons
source share