title: How to assign a string id to UI elements.
body: <p>I'm developing an app on android and I am generating UI elements in a loop. But I need these elements to have an id with letters and numbers, for example <code>"rl1"</code> or <code>"rl2"</code>. I was trying to use the method <code>RelativeLayout.setId()</code> but, that method only accepts <code>int</code>. Is there a way I can set an ID as I want without being limited to numbers?</p>
  
  <p>Thanks. </p>
  
  <p>Here is the code I am trying to make work. </p>
  
  <pre><code>for (int i=1; i &lt; 10; i++)
  {
      //gets the frameview where the elements will be created.
      String LinearLayoutId = "frameview1";
      int resID = getResources().getIdentifier(LinearLayoutId, "id", "com.myapp.ERS");
      LinearLayout linearLayout = (LinearLayout)findViewById(resID);
  
      //creates the RelativeLayout that will hold the ImageIcon and the TextView
      RelativeLayout rl = new RelativeLayout(this);
      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.MATCH_PARENT,40 );
      rl.setLayoutParams(lp);
      rl.setId("rl"); /// &gt;&gt;&gt;&gt; I would like here to set and ID of "rl1" for example.
      rl.setBackgroundDrawable(getResources().getDrawable(R.drawable.bk36));
  
      //creates the image icon within the layout at the left side
      ImageView image = new ImageView(this);
      lp = new RelativeLayout.LayoutParams(
              40,RelativeLayout.LayoutParams.MATCH_PARENT );
  
      image.setLayoutParams(lp);
      String imageicon = "icon_"+i;
      resID = getResources().getIdentifier(imageicon, "drawable", "com.myapp.ERS");
      image.setImageDrawable(getResources().getDrawable(resID));  //sets the icon
      rl.addView(image); //adds the ImageView to the relative layout
  
  
      //creates the TextView within the layout with a 40 margin to the left
      TextView tv = new TextView(this);
      lp = new RelativeLayout.LayoutParams(
                  RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT );
      lp.setMargins(40, 0, 0, 0);
      tv.setLayoutParams(lp);
      String textViewID = "tv"+i;
      resID = getResources().getIdentifier(textViewID, "string", "com.myapp.ERS");
      tv.setText(getResources().getString(resID));
      tv.setTextColor(Color.BLACK);
      tv.setTextSize(25);
      rl.addView(tv);//adds the TextView to the relative layout
      rl.setOnClickListener(mAddListener);
      linearLayout.addView(rl);//adds the RelativeLayout to the LinearLayout
  }
  </code></pre>
  
  <p>and then I have the OnCLickListener like this... </p>
  
  <pre><code>private OnClickListener mAddListener = new OnClickListener()
  {
      public void onClick(View v){
          Intent intent;
          Bundle bundle;
  
          String id = getResources().getResourceEntryName(v.getId());
          id = id.replaceAll("\\D+","");
          int value = Integer.parseInt(id);
  
          intent = new Intent(ERS.this, ShowInfo.class);
          bundle = new Bundle();
          bundle.putInt("key", value);  
          System.out.println(v.getId());
          intent.putExtras(bundle); 
          startActivity(intent);
      }
  };
  </code></pre>
  
  <p>I have tried to set up numeric IDs, but then when I Look for them with: </p>
  
  <pre><code>String id = getResources().getResourceEntryName(v.getId());
  </code></pre>
  
  <p>It can't find them. </p>
  
  <p>I had all of this in an <code>xml</code> file to begin with, but it was really long because there are about forty items in the list, and it was complicated for me to go and change a letter for example in all of them.  I came up with this idea to generate them at runtime in a <code>for loop</code>. I am testing in the meantime with ten, but I can't get it to work.  </p>
  
  <p>If I am doing something incorrect, then pardon me, but I am new to this.</p>