tags:

views:

79

answers:

0

I'm developing an Android application, and I have a 2 tabbed interface, created by having separate TabSpec's for each tab within a TabHost. I have separate activities for each Tab - let's call them TabPhotos and TabAlbums. The layout for each tab is a ListView of records (e.g. photos and albums, respectively).

From the TabPhoto context menu, by long-holding a photo, I can either choose an existing album to add a photo to, or I can create a new album on the fly to add a photo to. If I choose to add it to a new album, I need to refresh the ListView for TabAlbums to show this new album. Normally, I would be able to refresh the ListView for TabAlbums from within that class by calling "fillAlbumsView()":

public class TabAlbums extends ListActivity {
    private DbAdapter mDbHelper;
    private Cursor mAlbumsCursor;    

private void fillAlbumsView() {
        if (mAlbumsCursor == null) {
            mAlbumsCursor = mDbHelper.fetchAllAlbums();
            startManagingCursor(mAlbumsCursor);
        }
        else {
            mAlbumsCursor.requery();
        }

        String[] from = new String[]{DbAdapter.KEY_ALBUM_TITLE};

        int[] to = new int[]{R.id.album_list_row_title};

        SimpleCursorAdapter album = 
            new SimpleCursorAdapter(this, R.layout.albums_list_row, mAlbumsCursor, from, to);
        setListAdapter(albums);
    }

However, since the call to refresh the TabAlbums view needs to happen from the onActivityResult() method of the TabPhotos class, I'm not sure how to handle that.

I've seen many people strongly advocate for having separate views for Tabs, instead of separate activities, but I am a novice Android programmer and it seems like the work involved with tracking which tab is active/inactive is more trouble than it's worth. Plus, from the example I'm trying to follow (e.g. the source for Android's native Music player), I can't seem to follow what they are doing with Uri's for calling activities.

What do I do? Do I refresh each tab every time someone clicks it? Do I create some utility class that can somehow refresh both tab's views? Can I call, from the TabPhotos activity, the parent class of TabPhotos and then call the TabAlbums child activity? Any help would be very much appreciated. Thank you.