2012-03-06 36 views
0

我一直試圖通過使其鏈接到xml文件來將此alertDialog設置爲線性視圖。但它不工作。任何幫助,將不勝感激,感謝名單將AlertDialog設置爲線性視圖

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setMessage("Are you sure you want to exit?") 
    .setCancelable(false) 
    .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 
      MyActivity.this.finish(); 
     } 
    }) 
    .setNegativeButton("No", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 
      dialog.cancel(); 
     } 
    }); 
AlertDialog alert = builder.create(); 

回答

0

我能得到你的權利:你要放置一個AlertDialog內的LinearLayout?

LayoutInflater inf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
LinearLayout myLayout = (LinearLayout) inf.inflate(R.layout.dialog_layout, null); 

builder.setView(myLayout); 

只需用XML佈局更換dialog_layout。你也不需要builder.setMessage("Are you sure you want to exit?")了。

+0

我將如何引用xml中的按鈕名稱它不像只是設置一個名爲button = yes的變量;你有任何想法,不管thanx – Hashey100 2012-03-06 14:53:27

+0

在XML中說'

+0

Ty老兄我會去工作 – Hashey100 2012-03-06 15:03:49