ListView getting deleted onbackpress

Posted by adohertyd on Stack Overflow See other posts from Stack Overflow or by adohertyd
Published on 2012-11-11T22:56:43Z Indexed on 2012/11/11 22:59 UTC
Read the original article Hit count: 139

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);
            }
        });

    }

}

© Stack Overflow or respective owner

Related posts about android

Related posts about android-listview