2012-05-18 22 views
0

我試圖使用下面的代碼爲我的手機應用程序顯示AlertDialog。當我的應用程序運行到入口點時,AlertDialog沒有顯示給用戶。AlertDialog沒有出現(在後臺)

手機屏幕變成深色被鎖定。但是,我可以按手機的返回按鈕讓應用程序轉到下一步,如的行爲取消功能按下。

AlertDialog似乎隱藏在應用程序背景中。我想將它稱爲前景。

怎麼辦?

順便說一下,LogCat上沒有顯示錯誤消息。

有人可以指出我錯在哪裏,或者我可以提供哪些其他信息?

謝謝!

AlertDialog.Builder builder1 = new AlertDialog.Builder(Mainx.this); 
builder1.setTitle(getResources().getString(R.string.str_sel_player)); 
LayoutInflater inflater = LayoutInflater.from(this); 
View functionListView = inflater.inflate(R.layout.dialog_pickitem_action,null); 
builder1.setView(functionListView); 
mlistView = (ListView) functionListView.findViewById(R.id.m_functions_listview); 
mlistView.setAdapter(new ArrayAdapter<String>(this,     
    android.R.layout.simple_list_item_1, mPlayers)); 
selDialog = builder1.create(); 
selDialog.show(); 

回答

0

這兩行代碼來調用警告對話框方法

AlertDialog diaBox = makeAndShowDialogBox(); 
diaBox.show(); 

警告對話框代碼

private AlertDialog makeAndShowDialogBox(){ 
AlertDialog myQuittingDialogBox =new AlertDialog.Builder(this) 
    //set message, title, and icon 
    .setTitle(resource.getString(R.string.str_pick_app)) 
    .setMessage(resource.getString(R.string.savesettings)) 
    .setIcon(R.drawable.menu_settings) 

    .setPositiveButton(resource.getString(R.string.ok), new DialogInterface.OnClickListener() { 

     public void onClick(DialogInterface dialog, int whichButton) { 

      //write code as acc to your requirement 

      dialog.dismiss(); 

     } 

    }) 

    .create(); 
//startActivity(intet); 
    return myQuittingDialogBox; 

} 
+0

由於拉姆的快速一起使用的ShowDialog()反應!我的應用程序的appBackDialog的初始化是在Activity已經啓動的情況下編碼的(意味着它對於這個Activity是全局可變的)。和「appBackDialog.show();」被編碼在我的代碼的末尾。我不確定你的建議有什麼區別或擔憂? – cmh

+0

順便說一下,我不需要DialogInterface來實現Yes/No按鈕。此AlertDialog框將僅顯示用於用戶選擇的功能頭寸列表。 – cmh

+0

因爲我更正了發佈的代碼部分。 「appBackDialog.show();」 shound更改爲「selDialog.show();」爲我的prevouse評論。抱歉,堅固! – cmh

0

這很奇怪。

你可以嘗試使用onCreateDialog()

覆蓋活動的

對話框onCreateDialog(INT ID)

然後調用的ShowDialog(INT ID)

+0

嗨,江,感謝您的建議!該對話框仍未通過實施所提供的方法顯示。它像以前一樣隱藏在背景中。 – cmh