I’m getting a weird problem when refreshing my ListView, it works fine until the device is rotated and then when refreshing it again it goes completely blank. This can only be fixed by rotating the device again(as it is also refreshed in onCreate()) but then whenever its refreshed again it goes blank. Problem persists until app is restarted.
EDIT:
Some code:
private ListView contactlist = null;
private static MatrixCursor matrixcursor = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contactlist = (ListView) findViewById(R.id.contactlist);
if (savedInstanceState == null) {
matrixcursor = new MatrixCursor(new String[] {"_id","name","one","two","three","four"});
} else {
contactlist.setAdapter(new listCursorAdapter(this,matrixcursor));
}
}
this works fine but whenever:
contactlist.setAdapter(new listCursorAdapter(this,matrixcursor));
is called after onCreate() and after the device has been rotated the ListView goes blank.
Well I managed to fix it by making
contactliststatic:I have no idea why this worked(just did a trial/error for a couple of hours) so if anyone could explain it that would be great.