2010-07-01 85 views
0

我有一個TextViewer Activity,它有一個按鈕,當我點擊它時,我想彈出AlertDialog列表。我跟着這個link,但它不工作(沒有彈出)。我相信背景是錯誤的。 我用下面的代碼:自定義AlertDialog沒有顯示

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.resources); 
    ImageButton btnlist = (ImageButton)findViewById(R.id.list); 
    btnlist.setOnClickListener(new View.OnClickListener() { 
      public void onClick (View v){     

       if (Vars.bookchapter>1){ 
       final CharSequence[] items = {"Red", "Green", "Blue"}; 
       Context mContext = getBaseContext(); 
       AlertDialog.Builder builder = new AlertDialog.Builder(mContext); 
       builder.setTitle("Pick a color"); 
       builder.setItems(items, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int item) { 
         Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); 
        } 
       }); 
       AlertDialog alert = builder.create(); 
       }else{ 
       //Nothing 
       } 
      }});   
    } 
     } 

回答

5

您還沒有叫show()方法。這樣做:

AlertDialog alert = builder.create(); 
alert.show(); 
+0

這是令人尷尬:( 感謝 – OkyDokyman 2010-07-01 17:46:04

+3

那天正好最好的程序員也。 – Cristian 2010-07-01 18:00:51

相關問題