新しく開発されたAndroid開発版です。 私は3つの異なるタブを持つアプリケーションを開発しています。私はすべてのタブと共通のメニューオプション(AboutやRefreshなど)を各個別の必要に応じて個別のメニューに必要とします。さまざまなタブに共通するメニュー
myappのメイン():他の[インベントリ]タブで
public class MyApp extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Bundles.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("bundles").setIndicator("Bundles",
res.getDrawable(R.drawable.ic_tab_bundle_grey))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Policies.class);
spec = tabHost.newTabSpec("policies").setIndicator("Policies",
res.getDrawable(R.drawable.ic_tab_policy_grey))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Inventory.class);
spec = tabHost.newTabSpec("Inventory").setIndicator("Inventory",
res.getDrawable(R.drawable.ic_tab_settings_grey))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.menu, menu);
return true;
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.about:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.refresh:
Intent j = new Intent(this, RefreshAgent.class);
startActivity(j);
break;
// more buttons to go here later
}
}
:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.settings_menu, menu);
return true;
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.register:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.reregister:
Intent j = new Intent(this, Reregister.class);
startActivity(j);
break;
case R.id.accountsettings:
Toast.makeText(this, "Account Settings", Toast.LENGTH_LONG).show();
break;
}
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.register:
Toast.makeText(this, "Registration Not implemented!", Toast.LENGTH_LONG).show();
return true;
case R.id.reregister:
Toast.makeText(this, "Re Registration Not implemented!", Toast.LENGTH_LONG).show();
//TODO : Use refresh agent class
//startActivity(new Intent(this, RefreshAgent.class));
return true;
case R.id.accountsettings:
//Intent j = new Intent(this, RefreshAgent.class);
//startActivity(j);
Toast.makeText(this, "Account Settings", Toast.LENGTH_LONG).show();
break;
}
return false;
実装ディスプレイ上約及びその他の2つのタブを更新しますが、[インベントリ]タブで、それは2つだけ定義されているが表示されます[インベントリ]タブにあります。
ご協力いただきありがとうございます。
素晴らしい! inflater.inflate(R.layout.menu、menu)を追加していただきありがとうございます。在庫タブの下でそれはうまくいった:) –