Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:49:00+00:00 2026-06-09T03:49:00+00:00

I have a ListView, which displays a list of notes taken from a table

  • 0

I have a ListView, which displays a list of notes taken from a table in SQLiteDatabase with ArrayAdapter.

public class NotepadActivity extends ListActivity {

protected static final int ADD_NEW_NOTE = 0;
protected static final int EDIT_NOTE = 1;
ArrayAdapter<Note> adapter;
NotesManager manager;
private Note nNoteToDelete;
ArrayList<Note> lstAllNotes;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    findViewById(R.id.btnAddNewNote).setOnClickListener(addNewNote);
    manager = new NotesManager(this);
    lstAllNotes = manager.getAllNotes();
    adapter = new ArrayAdapter<Note>(this, R.layout.note, lstAllNotes);
    setListAdapter(adapter);
    getListView().setOnItemClickListener(editNote);
    registerForContextMenu(getListView());
}

When I click on an Item in this ListView, it takes this Note object to the EditNote activity:

private OnItemClickListener editNote = new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        Note currNote = (Note)parent.getItemAtPosition(position);

        int curr_note_id = currNote.getId();
        String curr_note_title = currNote.getTitle().toString();
        String curr_note_details = currNote.getDetails().toString();

        Intent editNote = new Intent(NotepadActivity.this, EditNote.class);
        editNote.putExtra("CURR_NOTE_ID", curr_note_id);
        editNote.putExtra("CURR_NOTE_TITLE", curr_note_title);
        editNote.putExtra("CURR_NOTE_DETAILS", curr_note_details);

        startActivityForResult(editNote, EDIT_NOTE);

    }
};

I can edit the title of the note in there and the content. When I hit the Save button, it sends back to the main activity the Strings of Title and the Details and the ID int:

public class EditNote extends Activity implements OnClickListener {

int curr_note_id;
String curr_note_title;
String curr_note_details;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.editnote);

    curr_note_id = getIntent().getExtras().getInt("CURR_NOTE_ID");
    curr_note_title = getIntent().getExtras().getString("CURR_NOTE_TITLE");
    curr_note_details = getIntent().getExtras().getString(
            "CURR_NOTE_DETAILS");

    ((EditText) findViewById(R.id.edtTitle)).setText(curr_note_title);
    ((EditText) findViewById(R.id.edtDetails)).setText(curr_note_details);

    findViewById(R.id.btnSave).setOnClickListener(this);
    findViewById(R.id.btnCancel).setOnClickListener(this);
}

@Override
public void onClick(View v) {

    switch (v.getId()) {
    case R.id.btnSave:
        String strNoteTitle = ((EditText) findViewById(R.id.edtTitle)).getText().toString().trim();
        String strNoteDetails = ((EditText) findViewById(R.id.edtDetails)).getText().toString().trim();

        if (!strNoteTitle.equals("")) {

            Intent data = new Intent();
            data.putExtra("NOTE_ID", curr_note_id);
            data.putExtra("NOTE_TITLE", strNoteTitle);
            data.putExtra("NOTE_DETAILS", strNoteDetails);
            setResult(RESULT_OK, data);
            finish();
        } else {
            ((EditText) findViewById(R.id.edtTitle))
                    .setError("A note must contain a title");
        }

        break;
    case R.id.btnCancel:
        setResult(RESULT_CANCELED);
        finish();
        break;
    }

}

}

And in the main activity it should update the DB and the ListView with the new Title, if there were changes. My code does update the DB, but I don’t see the change in the ListView immediately, only if I exit the app and open it again. Here’s the code (watch the second case, EDIT_NOTE):

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
        case ADD_NEW_NOTE:
            String noteTitle = data.getExtras().getString("NOTE_TITLE");
            String noteDetails = data.getExtras().getString("NOTE_DETAILS");
            Note nNewNote = new Note(-1, noteTitle, noteDetails);
            adapter.add(nNewNote);
            manager.addNote(nNewNote);
            break;
        case EDIT_NOTE:
            int noteID = data.getExtras().getInt("NOTE_ID");
            noteTitle = data.getExtras().getString("NOTE_TITLE");
            noteDetails = data.getExtras().getString("NOTE_DETAILS");
            nNewNote = new Note(noteID, noteTitle, noteDetails);
            Toast.makeText(NotepadActivity.this, noteTitle + "\n" + noteDetails, Toast.LENGTH_SHORT).show();
            manager.updateNote(nNewNote);           
            break;
        }

    }
    super.onActivityResult(requestCode, resultCode, data);
}

After manager.updateNote(nNewNote); I tried to use adapter.notifyDataSetChanged(); but that didn’t work – I didn’t see the change in the ListView. Perhaps I used it wrong, perhaps I should use something else…

So how can I make the ListView refresh? How can I see change immediately, without restarting the app?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:49:01+00:00Added an answer on June 9, 2026 at 3:49 am

    When you return from the edit activity, set the list adapter again to refresh the ListView. You have to manually refresh the ListView each time if you want to see any updates. Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView which displays a list of string values. I want to
I have a listview, which displays a list of administrators, this list is held
I have a list (ListView) which which displays a lot of information, and what
I have a listview which displays items retrieved from the webpage. Each item in
Hi guys I have an activity which extends ListActivity and displays a listview which
I have a ListView which displays a list of items. When I click on
I have a listview which displays a list of Users (binds to UserListViewModel) -
I have a list view item which has a button and displays properties on
I have a ListView-like control that displays a list of items of various heights.
I have an activity that extends ListView. I populate my list with the results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.