Search code examples
androiddeveloper-toolsfindviewbyid

Android Developer Tools code generation for Views like Buttons, textfields


Does the following feature exist in Android Developer Tools.

After you have created your XML layout, is there a quick way to quickly import those views into your java code automatically.

This is to save you typing in the

EditText editText = (EditText) findViewById(R.id.search)

Is there some short cut which will automatically generate this code by looking at my XML file ?


Solution

  • This is not the exact answer but look at roboguice. It's dependency injection framework for Android.

    class RoboWay extends RoboActivity { 
    @InjectView(R.id.name)             TextView name; 
    @InjectView(R.id.thumbnail)        ImageView thumbnail; 
    @InjectResource(R.drawable.icon)   Drawable icon; 
    @InjectResource(R.string.app_name) String myName; 
    @Inject                            LocationManager loc; 
    
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main);
        name.setText( "Hello, " + myName ); 
    } 
    }