For some reason, the standard "Settings" button in the upper right corner disappeared when using ListVu. What is the problem and how to get it back? I will be grateful.

public class MainActivity extends ListActivity { String[] Buttons = new String[100]; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); for (int i=0;i<=99;i++){ Buttons[i]=Integer.toString(i+1); } // MyCustomAdapter forData= new MyCustomAdapter(this,Buttons); setListAdapter(new MyCustomAdapter(this,Buttons)); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { Intent intent = new Intent(MainActivity.this,SettingActivity.class); startActivity(intent); return true; } return super.onOptionsItemSelected(item); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Toast.makeText(this, position + " selected", Toast.LENGTH_LONG).show(); } } 
  • There are no problems in the code, except for the fact that you obviously need to make the adapter assignment ( setListAdapter(new MyCustomAdapter(this,Buttons)); ) to the list outside the loop. - JuriySPb
  • @ ЮрийСПб Thanks for the comment, but this did not affect the Settings button. When testing on a real device, this button is physical, but here is no way to press an emulator - Mihailenko 2015 at 4:56

1 answer 1

Try also override the onPrepareOptionsMenu method and return true from it:

 @Override public boolean onPrepareOptionsMenu (Menu menu) { return true; }