baron_bartek baron_bartek - 1 year ago 247
Java Question

setEnabled doesnt work in android

I have this code:

public TextView main_text;//begining of the class

main_text = (TextView) findViewById(; //inside OnCreate

main_text.setEnabled(false); //inside button handler

And now the part of Xml

android:text="@string/home_load" >


Why doesnt SetEnable work? It seems so obvious that it should.

Answer Source

What do you expect setEnabled(false) to do to a TextView?

If you want to hide the TextView, you should rather call setVisibility(View.INVISIBLE)

If you want to disable clicks, you should rather call setOnClickListener(null)

If you want the text to display in a disabled state, then you need to define the states for the view in a separate XML file.

For example textView.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">
    <item android:state_enabled="true" android:color="@color/enabled" />
    <item android:state_enabled="false" android:color="@color/disabled" />

And then in your TextView definition use

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download