您好我的应用程序中有一个4按钮菜单,我在菜单按钮中设置订单时遇到麻烦,我希望首先分享,刷新前2列和左下2列中的关闭和退出。< / p>
我需要订单: 现在 - &gt; 1.-关于,2.-刷新,3.-分享和4.-退出,
渴望 - &gt; 1.-分享,2.-刷新,3.-关于,和4.-退出
MENU XML
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="@+id/share"
android:icon="@drawable/ic_menu_share"
android:title="@string/share"/>
<item
android:id="@+id/refresh"
android:icon="@drawable/ic_menu_refresh"
android:title="@string/refresh"/>
<item
android:id="@+id/exit"
android:icon="@drawable/ic_exit_button"
android:title="@string/exit"/>
<item
android:id="@+id/about"
android:icon="@drawable/ic_about"
android:title="@string/about"/>
菜单活动
public boolean handleMenuSelect(MenuItem item) {
switch (item.getItemId()) {
case R.id.share:
String shareBody = "Conoce tu horoscopo diario "
+ activity.getString(R.string.app_name) + ", "
+ activity.getString(R.string.share_url);
Intent sharingIntent = new Intent(
android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent
.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
activity.startActivity(Intent.createChooser(sharingIntent,
"Share via"));
return true;
case R.id.refresh:
Intent refresh = new Intent(activity, MainActivity.class);
activity.startActivity(refresh);
return true;
case R.id.about:
String appVersion = activity.getString(R.string.about);
PackageInfo pInfo;
try {
pInfo = activity.getPackageManager().getPackageInfo(
activity.getPackageName(), 0);
appVersion = pInfo.versionName;
} catch (NameNotFoundException e) {
// TODO: logging
}
DialogInterface.OnClickListener dialogAboutClickListener = new Aboutlistener();
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(
activity.getString(R.string.about_text) + appVersion)
.setPositiveButton(activity.getString(R.string.ok),
dialogAboutClickListener).show();
return true;
case R.id.exit:
DialogInterface.OnClickListener dialogYesNoClickListener = new Exitlistener(
activity);
AlertDialog.Builder builderYesNo = new AlertDialog.Builder(activity);
builderYesNo
.setMessage(activity.getString(R.string.are_you_sure))
.setPositiveButton(activity.getString(R.string.yes),
dialogYesNoClickListener)
.setNegativeButton(activity.getString(R.string.no),
dialogYesNoClickListener).show();
return true;
default:
return activity.onOptionsItemSelected(item);
}
Mainactivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
MenuItem share = menu.findItem(R.id.share);
share.setEnabled(true);
MenuItem refresh = menu.findItem(R.id.refresh);
refresh.setEnabled(true);
MenuItem about = menu.findItem(R.id.about);
about.setEnabled(true);
MenuItem exit = menu.findItem(R.id.exit);
exit.setEnabled(true);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return new Mainmenu(this).handleMenuSelect(item);
}