0

I had a ListView that loads data from the SQLite database and onClickListener for each list that opens up to a new activity. My problem now is that when I press "Back" to go back to the previous activity with the ListView, it doesn't show.

How do I reload the list from database again? How do I go about it?

Does it have anything to do with notifyDataSetChanged()?

Please help.

Thank you.

EDITED:

Below are my codes to load the ListView under onCreate():

        ListView listContent = (ListView) findViewById(R.id.contentlist);
        mySQLiteAdapter = new SQLiteAdapter(this);
        mySQLiteAdapter.openToRead();

        Cursor cursor = mySQLiteAdapter.queueAll();
        startManagingCursor(cursor);

        String[] from = new String[] { SQLiteAdapter.KEY_CONTENT };
        int[] to = new int[] { R.id.text };

        SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.listrow, cursor, from, to);

        listContent.setAdapter(cursorAdapter);

        mySQLiteAdapter.close();

        //Onclick ListView setlistener
        listContent.setTextFilterEnabled(true);
        listContent.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Intent summaryIntent = new Intent(DocumentListActivity.this, ViewDocumentActivity.class);
                listTopic = ((TextView) view).getText().toString();

                summaryIntent.putExtra("SummTopic", listTopic);
                startActivity(summaryIntent);
            }
        });

So what to add in the Resume()?

4
  • 1
    You should add your load data code to onStart() or onResume(). The rest is pure guessing as you don't provide code... Commented Nov 27, 2012 at 13:30
  • Can you post your code? The listview have to show when you pressed back, thats a android lifecycle issue. Load from database in onResume() is not required, when nothing is changed content of database not changed. By a database with much entries it will be impair performance. Commented Nov 27, 2012 at 13:42
  • @WarrenFaith: See my edited part for codes. Commented Nov 27, 2012 at 13:53
  • @zennon: if onResume() is not the best way, how do I implement otherwise? Commented Nov 27, 2012 at 13:55

1 Answer 1

2

You can put your code to fetch data from database and adding it to ListView inside onResume(). So when you jump back to your previous Activity its onResume() will be called and your ListView will be loaded with the data from database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.