I have an android app that (on tablets) uses the master-detail flow to show a list of forecasts on the left and detailed information on the right. I want to be able to select the first item when the application loads.

I have code in the `onLoadFinished` method that sets the selected index. I implemented this because sometimes the user would select an item, and if they changed the orientation it would be off screen. I used this following method to ensure that once it loads the proper item is selected again:

```
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mForecastAdapter.swapCursor(data);

    // If we have a selected index - select it.
    if(mSelectedIndex != ListView.INVALID_POSITION) {
        mForecastListView.setSelection(mSelectedIndex);
    }
}

```

I tried adding an else statement that checked if a tablet was being used, to select the first item. The code was executed, but it seemed to happen before the listview actually loaded and the item was not selected. Where should I put the code to select the first item, upon app opening?

**EDIT**
Here is a method that I have tried, to no luck:

```
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mForecastAdapter.swapCursor(data);

    // If we have a selected index - select it.
    if(mSelectedIndex != ListView.INVALID_POSITION) {
        mForecastListView.setSelection(mSelectedIndex);
    } else if(mForecastAdapter.IsTwoPane()){
        mForecastListView.setSelection(0);
    }
}

```