Reputation:
I know java and but this is question for me that if "getMenuInflater().inflate(R.menu.main, menu)" is not from Activity Class, so why default project in android studio works well? In the following code, Activity class is a parent class. But there are not getMenuInflater() And inflate(....., ....) in Activity class. It is not reasonable.
package com.exaample.pro;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Upvotes: 0
Views: 3021
Reputation: 1006614
getMenuInflater()
is a method on Activity
, as you can see in the documentation.
inflate()
is a method on MenuInflater
, the type of object returned by getMenuInflater()
.
Upvotes: 1