我创建了两个对话框,我正在菜单中显示这些对话框。但是,当我点击搜索meu选项时,它与同步菜单选项重叠。我已经尝试了一切但没有解决方案。任何人都能告诉我解决方案。
我的代码:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
// Handle item selection
case R.id.Synch:
showDialog(SYNC_ALERT);
return true;
case R.id.searchid:
showDialog(SEARCH_ALERT);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case SEARCH_ALERT:
// Create out AlterDialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Search");
builder.setCancelable(true);
LayoutInflater inflater = this.getLayoutInflater();
View searchView= inflater.inflate(R.layout.search_dialog, null);
builder.setView(searchView);
Searchtxt = (EditText) searchView.findViewById(R.id.search_text);
builder.setPositiveButton("Search", new searchOkOnClickListener());
builder.setNegativeButton("Cancel", new searchCancelOnClickListener());
AlertDialog dialog = builder.create();
dialog.show();
case SYNC_ALERT:
AlertDialog.Builder alertbuilder = new AlertDialog.Builder(this);
alertbuilder.setMessage("Synchronization");
alertbuilder.setCancelable(true);
LayoutInflater buildinflater = this.getLayoutInflater();
View SyncView= buildinflater.inflate(R.layout.sync_layout, null);
alertbuilder.setView(SyncView);
defaultchkbox = (CheckBox)SyncView.findViewById(R.id.defaultchkbox);
after15mint = (CheckBox)SyncView.findViewById(R.id.after15mint);
afternmint = (CheckBox)SyncView.findViewById(R.id.afternmint);
alertbuilder.setPositiveButton("Save Changes", new syncOkClickListener());
alertbuilder.setNegativeButton("Cancel", new syncCancelClickListener());
AlertDialog alertdialog = alertbuilder.create();
alertdialog.show();
}
return super.onCreateDialog(id);
}
答案 0 :(得分:2)
我对你的问题不太确定,所以我假设你在点击搜索菜单选项时得到了syn对话框。如果是这种情况,你应该在开关的每个案例之间放置。
switch (id)
{
case SEARCH_ALERT:
..................
break;
case SYNC_ALERT:
.................
}