I have the following activity xml file:
I would like to generate all the views variables in the java file base on their name.
For this example:
public class RegisterActivity extends AppCompatActivity {
private EditText editText_firstname;
private TextView label_lastname;
// .. So on
private void setup_views() {
editText_firstname = (EditText) findViewById(R.id.editText_firstname);
label_lastname = (TextView) findViewById(R.id.label_lastname);
// .. So on
}
}
It very frustrating to do it all over again for any new activity, and I seems to basic to not be in android studio.
So, how do I do it?
Thanks in advance.
in java for did not develop findviewByid()
you can use dataBinding library like Butter Knife
or use android native DataBinding
如上所述的数据绑定或切换到 Kotlin,您将不需要findViewById
在 Java 中它可能令人沮丧,但如果你切换到 Kotlin,使用这个伟大的 Anko库会更容易绘制一个 lyaout
Android Studio 有一个插件可以让你这样做,请参考以下链接获取插件: https : //plugins.jetbrains.com/plugin/7595-android-code-generator
In the recent release of Android API, ViewBinding is the recommended way to manipulate view components.
However, if you really need the classic findViewById(), here are several plugins that you can use in Android Studio:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.