当 android 设备处于横向模式时,菜单不起作用

When android device is in landscape mode menu doesn't work

当 select 在横向模式下使用菜单选项时它似乎不起作用,它只有一个进度加载器但是在纵向模式下我可以 select 菜单项选项并且符合预期任务,它加载新的加载程序并在 gridview 中显示项目。

public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<List<MovieImageData>>{

private final String LOG_TAG = MainActivity.class.getSimpleName();
//API KEY
private static final String API_KEY = "";

private static final String BASE_SORT_URL = "http://api.themoviedb.org/3/movie";
//Popular movie query
private static final String POPULAR_MOVIES_TAG = "/popular?api_key=";
//Top rated movie query
private static final String TOP_RATED_MOVIES_TAG = "/top_rated?api_key=";

private static final String POPULAR_MOVIES_URL = BASE_SORT_URL + POPULAR_MOVIES_TAG + API_KEY;
private static final String TOP_RATED_MOVIES_URL = BASE_SORT_URL + TOP_RATED_MOVIES_TAG + API_KEY;

private static String currentURL = POPULAR_MOVIES_URL;
static boolean hasLoaderOne = false;
MoviePosterAdapter adapter;
GridView moviePosterGridView;

View progress;

private static ArrayList<MovieImageData> movieData;

//Movie base
private static final String MOVIEDB_BASE_URL = "http://api.themoviedb.org/3/movie";
//Image base URL
private static final String MOVIEDB_IMAGE_BASE = "http://image.tmdb.org/t/p/w185/";

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

    progress = findViewById(R.id.loading_spinner);

    if(savedInstanceState == null || !savedInstanceState.containsKey("movie")) {
        Log.i(LOG_TAG, "Ent======================================================================");
        progress.setVisibility(View.GONE);
        getLoaderManager().initLoader(0, null, this).forceLoad();
    }else {

        movieData = savedInstanceState.getParcelableArrayList("movie");
        updateUi(movieData);
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.settings, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

        case R.id.popular:
            currentURL = POPULAR_MOVIES_URL;
            getLoaderManager().getLoader(0).forceLoad();
            progress.setVisibility(View.VISIBLE);
            hasLoaderOne = false;
            return true;


    case R.id.top_rated:

            currentURL = TOP_RATED_MOVIES_URL;
            getLoaderManager().initLoader(1, null, this).forceLoad();
            hasLoaderOne = true;
            progress.setVisibility(View.VISIBLE);
            return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putParcelableArrayList("movie", movieData);
    super.onSaveInstanceState(outState);
}

@Override
public Loader<List<MovieImageData>> onCreateLoader(int id, Bundle args) {
    Log.i(LOG_TAG, "LOADER============================");
    progress.setVisibility(View.VISIBLE);
    return new MovieImageLoader(MainActivity.this, currentURL);
}

@Override
public void onLoadFinished(Loader<List<MovieImageData>> loader, List<MovieImageData> data) {
    progress.setVisibility(View.GONE);
    movieData = new ArrayList<MovieImageData>();
    movieData.addAll(data);
    updateUi(movieData);
}

@Override
public void onLoaderReset(Loader<List<MovieImageData>> loader) {
    progress.setVisibility(View.GONE);
    moviePosterGridView.setAdapter(null);
}

public void updateUi(final List<MovieImageData> moviePosterData){

    // Create a new {@link ArrayAdapter} of earthquakes
    adapter = new MoviePosterAdapter(this, moviePosterData);

    TextView noItemFound = (TextView) findViewById(R.id.no_list);
    // Find a reference to the {@link ListView} in the layout
    moviePosterGridView = (GridView) findViewById(R.id.gridview);
    moviePosterGridView.setEmptyView(noItemFound);

    if(!isOnline()){
        noItemFound.setVisibility(View.VISIBLE);
    }else{
        //noItemFound.setText("No earthquakes found!");
    }


    // Set the adapter on the {@link ListView}
    // so the list can be populated in the user interface
    moviePosterGridView.setAdapter(adapter);
}

public boolean isOnline() {
    ConnectivityManager cm =
            (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

}

风景模式中发生的事情的图片

加载程序会继续,直到您将其旋转回纵向模式后才会结束。

Try this,

<activity
   android:name=".MainActivity"
   android:configChanges="orientation|screenSize"
  />