我有10個活動擴展了baseActivity。我的BaseActivity基本上有一個幫助菜單圖標。當用戶按下幫助菜單圖標時,我應該顯示該活動的幫助菜單。我怎樣才能知道哪些活動稱爲幫助菜單,所以我知道該XML資源顯示如何知道哪個活動點擊了按鈕?
public class BaseActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.help_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.help_menu_item:
displayHelpMenu();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
protected void displayHelpMenu(){
// I will load the xml to the textview and display it in dialog. How can I know which xml resource to load
}
}
偉大的解決方案。我喜歡替代品..接受:) – Snake