当前位置: 动力学知识库 > 问答 > 编程问答 >

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 ?

网友答案:

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 ); 
} 
} 
网友答案:

No. Sorry.

What are you trying to accomplish by finding all of your views? Maybe there is another shortcut that will help you.

分享给朋友:
您可能感兴趣的文章:
随机阅读: