簡體   English   中英

自定義首選項中的Android按鈕自動啟用

[英]Android Button in Custom Preference gets enabled automatically

我的應用程序中有一個自定義首選項,它由一個textview和一個按鈕組成,並放在首選項屏幕中。 我在首選項的onCreateView中加載布局

LayoutInflater inflater =  (LayoutInflater)getContext(). 
getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.custom_preference, parent, 
false); 

在我的xml中,我將android:enabled =“ false”設置為按鈕,因為我想禁用它並稍后有條件地啟用它。 當我的首選項屏幕出現時,此按鈕被禁用,但是會在一秒鍾后自動啟用(我仍然沒有添加任何代碼來啟用此按鈕)。 另外,我發現自定義首選項的onCreateView不斷被調用一次。 有人可以幫我看看這里發生了什么嗎?

您確定您的按鈕已從xml禁用嗎? 我在使用TextView布局時遇到了此類麻煩。 android:enable="false"無法正常工作。 嘗試像這樣在onCreate方法的代碼中直接禁用按鈕(假設xml文件中的按鈕ID為@+id/button

Button myButton;

myButton = (Button)findViewById(R.id.button);

myButton.setEnable(false);

然后,您以后可以使用myButton.setEnable(true);啟用它myButton.setEnable(true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM