title: Cast String to TextView
body: <pre><code>String data="tv";
  </code></pre>
  
  <p>Also in my xml file i have a TextView called tv1.
  I have casted the textView in the Activity.</p>
  
  <pre><code>TextView tv1 = (TextView) findViewById(R.id.tv1);
  </code></pre>
  
  <blockquote>
    <p><strong>I want to cast the string into TextView...</strong></p>
  </blockquote>
  
  <p>so that I can perform this operation on string instead on tv1.</p>
  
  <pre><code>data.setText("abc"); // on the string..
  </code></pre>
  
  <p>Can i achieve this or not..Also how to dynamically assign an id to a textView.
  Thanx... </p>
  
  <p>This is my activity code:</p>
  
  <pre><code>public class Winnings extends Activity {
  
  TextView tv1, tv2, tv3, tv4, tv5, tv6, tv7, tv8, tv9, tv10, tv11, tv12,
          tv13, tv14, tv15;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.winnings);
      setupVariables();
  
      // TODO Auto-generated method stub
      backGroundToChange(7);
  }
  
  private void setupVariables() {
      // TODO Auto-generated method stub
      tv1 = (TextView) findViewById(R.id.TextView01);
      tv2 = (TextView) findViewById(R.id.TextView02);
      tv3 = (TextView) findViewById(R.id.TextView03);
      tv4 = (TextView) findViewById(R.id.TextView04);
      tv5 = (TextView) findViewById(R.id.TextView05);
  
      tv6 = (TextView) findViewById(R.id.TextView06);
      tv7 = (TextView) findViewById(R.id.TextView07);
      tv8 = (TextView) findViewById(R.id.TextView08);
      tv9 = (TextView) findViewById(R.id.TextView09);
      tv10 = (TextView) findViewById(R.id.TextView10);
  
      tv11 = (TextView) findViewById(R.id.TextView11);
      tv12 = (TextView) findViewById(R.id.TextView12);
      tv13 = (TextView) findViewById(R.id.TextView13);
      tv14 = (TextView) findViewById(R.id.TextView14);
      tv15 = (TextView) findViewById(R.id.TextView15);
  }
  
  void backGroundToChange(int position) {
  
  //What i want to do is this..
  
  
  String data = "tv" + position;
  
  //The casting of string into a TextView and so that I can perform this...
  
  data.setBackgroundResource(R.drawable.option_correct);
  
  // so by this way i don't need the switch and case that was actually used, shown below.....
  
  //We normally implement it this way
  
      /*
          switch (position) {
      case 1:
          tv1.setBackgroundResource(R.drawable.option_correct);
          break;
      case 2:
          tv2.setBackgroundResource(R.drawable.option_correct);
          break;
      case 3:
          tv3.setBackgroundResource(R.drawable.option_correct);
          break;
      case 4:
          tv4.setBackgroundResource(R.drawable.option_correct);
          break;
      case 5:
          tv5.setBackgroundResource(R.drawable.option_correct);
          break;
      case 6:
          tv6.setBackgroundResource(R.drawable.option_correct);
          break;
      case 7:
          tv7.setBackgroundResource(R.drawable.option_correct);
          break;
      case 8:
          tv8.setBackgroundResource(R.drawable.option_correct);
          break;
      case 9:
          tv9.setBackgroundResource(R.drawable.option_correct);
          break;
      case 10:
          tv10.setBackgroundResource(R.drawable.option_correct);
          break;
      case 11:
          tv11.setBackgroundResource(R.drawable.option_correct);
          break;
      case 12:
          tv12.setBackgroundResource(R.drawable.option_correct);
          break;
      case 13:
          tv13.setBackgroundResource(R.drawable.option_correct);
          break;
      case 14:
          tv14.setBackgroundResource(R.drawable.option_correct);
          break;
      case 15:
          tv15.setBackgroundResource(R.drawable.option_correct);
          break;
  
      default:
          break;
      }
                     */
  
  }
  </code></pre>
  
  <p>xml code....</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" &gt;
  
  &lt;ScrollView
      android:id="@+id/scrollView1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" &gt;
  
  
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical" &gt;
  
  
          &lt;TextView
              android:id="@+id/TextView15"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="5 Crore"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#D4A017"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/TextView14"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="1 Crore"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/TextView13"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="50 Lakhs"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
          &lt;TextView
              android:id="@+id/TextView12"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="25 Lakhs"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView11"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="12,50,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
  
          &lt;TextView
              android:id="@+id/TextView10"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="6,40,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#D4A017"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView09"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="3,20,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView08"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="1,60,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView07"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="80,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView06"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="40,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
  
          &lt;TextView
              android:id="@+id/TextView05"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="20,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#D4A017"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView04"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="10,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView03"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="5,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView02"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="2,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
  
          &lt;TextView
              android:id="@+id/TextView01"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/option_bar"
              android:gravity="center"
              android:text="1,000"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:textColor="#ffffff"
              android:textStyle="bold" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p></p>
  
  <p>Images used...</p>
  
  <p><img src="https://i.stack.imgur.com/fJsNQ.png" alt="option_bar"></p>
  
  <p><img src="https://i.stack.imgur.com/uv6ZK.png" alt="option_correct"></p>