title: Set button clickable property to false
body: <p>I need to disable the <code>click-event</code> for a button in Android. Just as a sample, I have tried doing the following. I have taken a <code>TextView</code> named it (entered a text) as <em>Name</em>. The condition checks if, <code>TextView</code> is empty button and clickable should be set to false. However this does not happen when the Toast is printed. Can somemone tell me the reason. Also if the text field is not empty I want to reset  the <code>clickable event</code> for button as true. </p>
  
  <p><strong>Java File:</strong></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><strong>XML file:</strong></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;Button 
          android:text="Button" 
          android:id="@+id/button1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>