在我的应用我有近8菜单和我有两种类型的用户管理和客户如何隐藏操作栏中的某些菜单?
为管理员,我需要显示所有8个马努斯和用户我需要证明2个菜单为用户
为我给这个
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.m_mymenu, menu);
return true;
}
后我的代码将在简历上我加入下面一个
@Override
public boolean onOptionsItemSelected(MenuItem item) {
SharedPreferences s = getSharedPreferences(my_New_SP, 0);
HashMap<String, String> map= (HashMap<String, String>) s.getAll();
int id = item.getItemId();
if (map.get("usage").equals("Admin"))
{
if (id == R.id.abc) {
Intent mypIntent = new Intent(this, Myp.class);
startActivity(mypIntent);
return true;
}
.
.
.
.
else if (id == R.id.web1) {
Intent webIntent = new Intent(this, Web.class);
startActivity(webIntent);
return true;
}
else if (id == R.id.about1) {
Intent aboutIntent = new Intent(this, About.class);
startActivity(aboutIntent);
return true;
}
}
if (map.get("usage").equals("User"))
{
if (id == R.id.web1) {
Intent webIntent = new Intent(this, Web.class);
startActivity(webIntent);
return true;
}
else if (id == R.id.about1) {
Intent aboutIntent = new Intent(this, About.class);
startActivity(aboutIntent);
return true;
}
}
return super.onOptionsItemSelected(item);
}
所以这里在选项菜单我想显示只有两个用户和8管理员..
但是,当我选择它作为用户我和能够看到所有的菜单和只有他们两个人正在..所以在这里我只想显示工作菜单remaning应隐藏..
任何一个可以建议我这样的..
这里的菜单是从Android的菜单不仅没有动态菜单...
感谢@Ranjhid库马尔先生,我在这里的时候我用这个在我的代码我收到错误的项目和“菜单”。请检查我的更新)的问题,我应该需要更改我的代码 –
@ Don'tBenegative尝试内onCreateOptionMenu(代码..看到我的编辑答案.. –
先生,请看到我的更新问题,先生......如果我跟着你我的代码我正在使用map.get(“usage”)。equals(“User”)from shared prefs .. at resume –