http://www.androidhive.info/2012/05/android-combining-tab-layout-and-list-view/の「タブ レイアウトとリストビュー」とhttp://wwwの「Android メニュー」を使用しています。 .androidhive.info/2011/09/how-to-create-android-menus/ . それらをマージしますが、機能しません。タブは機能しますが、メニューは機能しません。これが私のコードです。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class optionMenuActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
// Initiating Menu XML file (menu.xml)
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu, menu);
return true;
}
/**
* Event Handling for Individual menu item selected
* Identify single menu item by it's id
* */
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
Intent myList = new Intent();
switch (item.getItemId())
{
case R.id.menu_login:
// Single menu item is selected do something
// Ex: launching new activity/screen or show alert message
// Toast.makeText(optionMenuActivity.this, "Bookmark is Selected", Toast.LENGTH_SHORT).show();
myList = new Intent(optionMenuActivity.this, LoginActivity.class);
startActivity(myList);
return true;
case R.id.menu_save:
Toast.makeText(optionMenuActivity.this, "Save is Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_search:
Toast.makeText(optionMenuActivity.this, "Search is Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_share:
Toast.makeText(optionMenuActivity.this, "Share is Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_delete:
Toast.makeText(optionMenuActivity.this, "Delete is Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_quit:
// Toast.makeText(optionMenuActivity.this, "Preferences is Selected", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
// return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
「タブレイアウト」よりメイン
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
そして、これは私のmenu.xmlです
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item android:id="@+id/menu_login"
android:icon="@drawable/icon_bookmark"
android:title="Login" />
<item android:id="@+id/menu_save"
android:icon="@drawable/icon_save"
android:title="Save" />
<item android:id="@+id/menu_search"
android:icon="@drawable/icon_search"
android:title="Search" />
<item android:id="@+id/menu_share"
android:icon="@drawable/icon_share"
android:title="Share" />
<item android:id="@+id/menu_delete"
android:icon="@drawable/icon_delete"
android:title="Delete" />
<item android:id="@+id/menu_quit"
android:icon="@drawable/icon_preferences"
android:title="Quit" />
</menu>
そして最後に、私のマニフェストです。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".WorkDroid5"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Inbox Activity -->
<activity android:name=".AnnouncementActivity" />
<!-- Outbox Activity -->
<activity android:name=".HomeworkActivity" />
<!-- Profile Activity -->
<activity android:name=".TimetableActivity" />
<activity android:name=".tt_Friday" />
<activity android:name=".ttFinalDetails" />
<activity android:name=".TimetableAdapter" />
<activity android:name=".tt_Thursday" />
<activity android:name=".tt_Monday" />
<activity android:name=".tt_Tuesday" />
<activity android:name=".tt_Wednesday" />
<activity
android:name=".RegisterActivity"
android:label="Register New Account" >
</activity>
<activity
android:name=".LoginActivity"
android:label="Login to your Account" >
</activity>
<activity
android:name=".optionMenuActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.example.OPTIONMENUACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<!-- Internet Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
誰の助けにも感謝します( ':