2013-04-24 142 views
0

我已經創建了兩個對話框,並且我正在用菜單方式激活這些對話框。但是,當我點擊搜索meu選項時,它將與同步菜單選項重疊。我嘗試了一切,但沒有解決方案。任何人都可以告訴我解決方案。Android菜單選項重疊對話框

我的代碼:

@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

put action_menu.xml – 2013-04-24 07:33:17

回答

2

我不太清楚你的問題,所以我假設你在搜索菜單選項,點擊時,你得到的SYN對話框。如果是這樣的話,你應該在交換機的每個情況之間進行中斷。

switch (id) 
{ 
    case SEARCH_ALERT: 
    .................. 
    break; 

    case SYNC_ALERT: 
    ................. 

}