ListView getting deleted onbackpress
- by adohertyd
I have a listview in my mainactivity that makes a call to a database to populate it. When an item on the listview is clicked it starts a new activity showing the details of the item that was clicked. When the back button is pressed the listview is not displayed again.
What could be the problem? This is the entirety of my mainactivity:
public class MainActivity extends ListActivity {
Button bAddMod;
private ModuleDB db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new ModuleDB(this);
db.open();
fillList();
db.close();
bAddMod = (Button) findViewById(R.id.btnAddMod);
bAddMod.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, AddModule.class);
startActivity(i);
}
});
}
private void fillList() {
ListView lv = getListView();
Cursor curs = db.getData();
startManagingCursor(curs);
MyCursorAdapter adapter = new MyCursorAdapter(getApplicationContext(), curs);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Intent k = new Intent(MainActivity.this, ModuleDetails.class);
k.putExtra("mod_id", id);
startActivity(k);
}
});
}
}