我有一個簡單的程序來顯示一個對話框,其中包含edittext視圖,並聽取正/負按鈕,在每個按鈕中執行自定義操作(讀取edittext並保存其內容到一個活動變量)。Android對話框界面獲取內部對話框視圖
當我看不到任何方法從對話框界面恢復當前對話框時(然後,我無法恢復對話框中的任何視圖),問題就出現了。
也許這是一個noob問題,但經過一些谷歌搜索,我沒有人回答它。
我的代碼如下
LayoutInflater li = LayoutInflater.from(this);
View myView = li.inflate(R.layout.my_layout, null);
AlertDialog.Builder cDialog = new AlertDialog.Builder(this);
cDialog.setView(myView);
cDialog.setPositiveButton(R.string.start_download, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//here the code to retrieve dialog
}
});
cDialog.create();
約我在哪裏可以找到任何線索?
:
所以,你可以在你的活動代碼的任何地方調用你的對話框中的任意按鈕嗨slukian。我試過這樣做,但該實例來自DialogInterface類,而不是對話框。 DialogInterface不提供findViewById方法...所以檢索給定對話框的內容是沒有用的。 – user1220817 2012-03-19 14:05:09
@ user1220817'dialog'參數是接收到點擊的對話框。將它轉換爲'AlertDialog',然後像這樣調用'findViewById()':EditText edit =(EditText)((AlertDialog)dialog).findViewById(R.id.editText1);'。 – Luksprog 2012-03-19 14:20:45
噢,真好!非常感謝你,沒有注意到DialogInterface可以直接對話。再次謝謝你 :) – user1220817 2012-03-19 14:31:48