Set button clickable property to false
<p>I need to disable the click event for a button in android.Just as a sample i tried doing the following.I have taken a text view named it(entered a text) as "Name" .The condition checks if text view is empty button clickable should be set to false.However this does not happen although the Toast is printed.Can somemone tell me the reason.Also if the text field is non empty i want to reset  the clickable event for button as true. </p>

<pre><code>public class ButtonclickabkeActivity extends Activity 
{
     TextView tv;
     Button btn;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.textView1);
        tv.setText("Name");
        btn=(Button)findViewById(R.id.button1);

        if(tv.getText().toString().length()!=0)
        {
            btn.setClickable(false);
            Toast.makeText(getApplicationContext(),""+tv.getText().toString().length(), Toast.LENGTH_LONG).show();
        }
        else
        {
            btn.setClickable(true);
        }



        btn.setOnClickListener(new View.OnClickListener() 
        {

            @Override
            public void onClick(View arg0) {

        Toast.makeText(getApplicationContext(), "Button clicked",Toast.LENGTH_LONG).show();

            }
        });
    }
}
</code></pre>

<p>The following is my XML file:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    &gt;
&lt;TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    /&gt;
&lt;TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/TextView&gt;
&lt;Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/Button&gt;
&lt;/LinearLayout&gt;
</code></pre>
