I have Main activity, in this activity I have one ListView with items taking from DB. Also here i have one button Add New Item. When user click on that button it open new activity. I'm opening new activity with Intent, but I'm not finishing Main activity, because the new activity is dialog and I need Main activity as a background.
Here I can add new item in DB. When item is added I'm finishing this activity. The Main activity is appearing on the screen. The problem is that the LitView is not updated, because this activity is already created before the adding the new item. So i want to reload main activity to update the ListView. But I don't know how.....or someone can give me other solution...
Populating the ListView from DB
public void PopulateListView() {
// Closing the cursor
// DEPRICATED!!
startManagingCursor(cursor);
// Set up mapping from cursor to view fields
String[] fromFieldNames = new String[] { DBAdapter.KEY_ITEM_NAME,
BAdapter.KEY_ITEM_USER, DBAdapter.KEY_ITEM_IMG, DBAdapter.KEY_ITEM_DATE_ADDED,
DBAdapter.KEY_ITEM_FAV };
int[] toViewIDs = new int[] { R.id.itemName, R.id.itemUser,
R.id.iconCopy, R.id.date, R.id.imgFav_M };
// Create adapter to map columns of DB to elements on UI
myCursorAdapter = new SimpleCursorAdapter(
this, // Context
R.layout.item_layout, // Row layout template
cursor, // Cursor (set of DB records)
fromFieldNames, // DB column names
toViewIDs // views ID to putt in list view
);
// Set the adapter for list view
myList.setAdapter(myCursorAdapter);
}
Add new item activity
private void addItem() {
String get_name, get_username, get_pass, get_cat, get_note;
int imageID = imageIDs[random.nextInt(imageIDs.length)];
get_name = name.getText().toString();
get_username = username.getText().toString();
get_pass = pass.getText().toString();
get_cat = cat.getText().toString();
get_note = note.getText().toString();
if (get_name.equals(""))
{
Alert("Insert Name...");
}
else if (get_username.equals(""))
{
Alert("Insert Username...");
}
else if (get_cat.equals(""))
{
myDb.insertRowInItems(get_name, get_username,
get_pass, "Other", get_note, imageID, isFav);
}
else
{
myDb.insertRowInItems(get_name, get_username,
get_pass, get_cat, get_note, imageID, isFav);
}
finish();
}