title: retrieve image resources from drawables dynamically by using names
body: <p>i am thinking of a simple program which will retrieve the appropriate image file (there will be many image files within drawable) from drawables depending on the user input from an EditText view. this input will match with 1 of the the png file names in my drawable resource folder. The program will thus retrieve the png file with the name that has the same name as the text in edittext. 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="enter the resource id and press getit button to retrieve it"
      /&gt;
  &lt;EditText
      android:id="@+id/edtxt"
      android:layout_width="100px" 
      android:layout_height="100px"    
      /&gt;
  &lt;EditText
      android:id="@+id/stedtxt"
      android:layout_width="100px" 
      android:layout_height="100px"    
      /&gt;    
  
  &lt;TextView  
      android:id="@+id/txtved"
      android:layout_width="60px" 
      android:layout_height="50px" 
  
      /&gt;
  &lt;Button
      android:id="@+id/Button01"
      android:layout_width="70px" 
      android:layout_height="70px"    
      android:clickable="true"
  /&gt; 
  </code></pre>
  
  <p>and following is my .java file.</p>
  
  <pre><code>package com.example.retrievedrawable;
  
  import java.lang.reflect.Field;
  import android.app.Activity;
  import android.content.res.TypedArray;
  import android.os.Bundle;
  import android.text.Editable;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.Toast;
  
  public class RetrieveDrawable extends Activity {
      private Editable resid;
      private String residst;
      private String TAG;
      private int drawableId;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          EditText edresid=  (EditText)findViewById(R.id.edtxt); 
          final EditText stdtxt=  (EditText)findViewById(R.id.stedtxt);
          Button setit = (Button) findViewById(R.id.Button01);
          final Editable resid=(Editable)edresid.getText();
          residst=resid.toString();
  
  
          try {
              Field field = com.example.retrievedrawable.R.drawable.class.getField(residst);
              try {
                  drawableId= field.getInt(null);
              } catch (IllegalAccessException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          } catch (NoSuchFieldException e) {
              Log.e(TAG, "Can't find resource drawable with name " + residst);
          } 
  
          setit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                stdtxt.setText(drawableId);
              }
  
              }); 
      }       
  
  }
  </code></pre>
  
  <p>i followed Vladimir's suggestions..but its giving me a force close..also once i get the id of the image in drawable..i want to set that image on the UI..</p>