2011-01-21 105 views
4

我想要一個EditTextPreference,如果EditText字段中沒有文本,將禁用OK按鈕。我創建了一個自定義的EditTextPreference類,我可以獲取EditText對象並設置TextWatcher,但我找不到禁用該按鈕的方法。它看起來像我沒有訪問對話框中的確定和取消按鈕。EditTextPreference禁用按鈕?

任何人都知道一種方法來獲得這些按鈕或做我想做的事情?

另一種選擇是嘗試從頭開始創建一個看起來像和模仿EditTextPreference的自定義對話框。

+0

沒有u得到一個soultion? – 2013-08-19 11:58:11

回答

9

下面是一個代碼示例,啓用/取決於onCheckValue函數是否返回truefalse禁用按鈕。

​​
+0

仍然沒有看到我如何訪問按鈕。我需要能夠禁用確定按鈕。你所建議的只是做我自己的對話。如果我採取這種方法,我只會建立一個自定義的Dialog類。 – Bob 2011-01-21 19:46:03

+0

我已經更新了答案。我自己檢查了這個新方法,它適用於我。 – inazaruk 2011-02-08 22:35:52

1

需要老EditTextPreference更改爲preference.xml新ValidatedEditTextPreference。

我做了以下內容:

舊代碼:

<EditTextPreference 
    android:dialogMessage="Please input your email" 
    android:dialogTitle="Set email" 
    android:key="Email" 
    android:summary="Your email" 
    android:title="-Missed call send to" android:defaultValue="[email protected]"/> 

新代碼:

<com.tanggod.missedcall2mail.ValidatedEditTextPreference 
    android:dialogMessage="Please input your email" 
    android:dialogTitle="Set email" 
    android:key="Email" 
    android:summary="Your email" 
    android:title="-Missed call send to" android:defaultValue="[email protected]"/>