从布局 XML 自动生成'View'类字段的工具?



我使用的是eclipse Android SDK,正如我所看到的,内置了代码生成器工具,可以从当前类生成getters()和setters()。我想知道是否有这样的工具可以从给定的布局中自动生成Android View类实例到当前类中。可能在onCreate()回调中自动实例化它们。

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:orientation="vertical"
        tools:context=".Main" >
        <TextView
            style="@style/Divider_Title"
            android:text="@string/pi_name_title" />
        <View style="@style/Divider" />
        <EditText
            android:id="@+id/et_firstname"
            style="@style/EditText"
            android:hint="@string/pi_first_name"
            android:inputType="textPersonName" />
        <EditText
            android:id="@+id/et_lastname"
            style="@style/EditText"
            android:hint="@string/pi_last_name"
            android:inputType="textPersonName" />
            ....

将为已存在的类SignIn 生成

public class SignIn extends FragmentActivity  {
    private EditText et_firstname;
    private EditText et_lastname; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registration);
        et_firstname = (EditText) findViewById(R.id.et_firstname);
        et_lastname = (EditText) findViewById(R.id.et_lastname);
                ...
    }

您可以查看以下链接

链接中的插件已被重构并更新为新功能(基本上已重写)。现在可以基于xml布局生成Activity、Fragment、Adapter。还可以为xml菜单文件生成与菜单相关的代码(处理操作)。并且具有可编辑的模板,因此用户对生成的数据有更多的控制权。

http://tmorcinek.github.io/android-codegenerator-plugin-eclipse/

我们开发了一个工具,可以自动创建视图变量,轻松设置自定义字体和监听器。您可以使用此

最新更新