Я работаю над андроидным самообучением Sunshine app, и у меня возникли проблемы с получением дополнительных пунктов меню в панели действий.Метод OnCreate не называется (приложение Sunshine)
Наиболее вероятная причина, по которой я нашел, заключается в том, что метод моего класса кадра не вызывается, и поэтому меню не накачивается.
Вот мой MainActivity код:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("MainActivity","OnCreate Started 1");
if (savedInstanceState == null) {
Log.d("MainActivity","OnCreate Started 2");
ForecastFragment MyFragment = new ForecastFragment();
if (MyFragment == null){
Log.d("MainActivity","OnCreate Started 3");
}
else{
getSupportFragmentManager().beginTransaction()
.add(R.id.container, MyFragment)
.commit();}
}
}
Вот теперь код моего класса ForecastFragment:
public class ForecastFragment extends Fragment {
public ForecastFragment() {
}
//@Override
protected void OnCreate(Bundle savedInstanceState){
Log.d("Forecastfragment","OnCreate Started");
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Inflate the menu; this adds items to the action bar if it is present.
inflater.inflate(R.menu.forecastfragment, menu);
}
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_refresh) {
FetchWeatherTask WeatherTask = new FetchWeatherTask();
WeatherTask.execute();
return true;
}
return super.onOptionsItemSelected(item);
}
Когда я запустить приложение, я не вижу, протоколирование, что метод OnCreate
класса ForecastFragment
.
Любые идеи?
Может быть, из-за верхний регистр «O» на 'OnCreate()' – beeb