title: Android custom attribute for TextView
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/14339333/how-to-read-custom-attributes-in-android">How to read custom attributes in Android</a>  </p>
  </blockquote>
  
  
  
  <p>Recently I read about custom attributes. I want to add a custom attribute to TextView.</p>
  
  <p>So far I have:</p>
  
  <p>attr file:</p>
  
  <pre><code>&lt;resources&gt;
      &lt;attr name="binding" format="string" /&gt;
      &lt;declare-styleable name="TextView"&gt;
          &lt;attr name="binding" /&gt;
      &lt;/declare-styleable&gt;
  </code></pre>
  
  <p>layout file:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
       xmlns:custom="http://schemas.android.com/apk/res/de.innosoft.android"
      android:id="@+id/RelativeLayout1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
          &lt;TextView
              custom:binding="test"/&gt;
  </code></pre>
  
  <p>Given a TextView</p>
  
  <pre><code>TextView tv = ...
  </code></pre>
  
  <p>How would I then get the value of that attribute (which ist "test")? I read about obtainStyledAttributes but do not know exactly how to use it here.</p>