开发者

Android Button in Custom Preference gets enabled automatically

I have a custom preference in my application which consists of a textview and a button and it is put in a preference screen. I load the layout in the onCreateView of the preference

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

In my xml, I have put android:enabled="false" for the button because I want to disable it开发者_StackOverflow and enable it conditionally later. When my preferencescreen comes up, this button is disabled, but gets enabled automatically in a second(I still haven't added any code to enable this yet). Also I find that the onCreateView of my custom preference keeps getting called again and again. Can someone please help me as to what is happening here?


Are you sure your button is disable from xml? I've faced this kind of trouble with textView layout. The android:enable="false" wasn't working. Try to disable your button directly in your code on the onCreate method like that (assuming your button id in the xml file is @+id/button)

Button myButton;

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

myButton.setEnable(false);

Then, you'll later be able to enable it with myButton.setEnable(true);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜