快速简便 Android 布局提取到 Java 代码
Quick and easy Android layout extraction into Java code
我正在使用 Eclipse 开发一个 Android 应用程序,我注意到创建 GetView() 方法对于我认为应该自动化的事情来说非常耗时,尤其是当一个典型的应用程序包含许多布局以充气。
我不是说实现监听器,而是简单地从新膨胀的布局中获取对每个元素的引用。
例如,当重写适配器的 getView() 方法时,前几行中的一行总是类似于以下内容:
View rootView = inflater.inflate(R.layout.fragmenta, container, false);
EditText edittext = (EditText) rootView.findViewById(R.id.input_user_name);
Button button = (Button) rootView.findViewById(R.id.show_user_name);
TextView textview = (TextView) rootView.findViewById(R.id.display_user_name);
每个布局都重复这种做法 inflation 并称我懒惰,但我正在寻找一种可能通过 Eclipse 插件自动执行此过程的方法。如果插件能够获取布局文件,提取所有具有 android:id 属性的元素,然后生成上面的 java 代码,那就太好了。
插件将获取文件 'fragmenta.xml':
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/input_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/show_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show user name" />
<TextView
android:id="@+id/display_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
并为 getView() 方法生成一些起始代码:
View rootView = inflater.inflate(R.layout.fragmenta, container, false);
EditText edittext = (EditText) rootView.findViewById(R.id.input_user_name);
Button button = (Button) rootView.findViewById(R.id.show_user_name);
TextView textview = (TextView) rootView.findViewById(R.id.display_user_name);
我相信这个插件对创建其他视图很有用,例如Activity -> onCreate(),片段 -> onCreateView(),适配器 -> getView()。
有这样的插件吗?
感谢您提供任何信息
我正在使用 Eclipse 开发一个 Android 应用程序,我注意到创建 GetView() 方法对于我认为应该自动化的事情来说非常耗时,尤其是当一个典型的应用程序包含许多布局以充气。 我不是说实现监听器,而是简单地从新膨胀的布局中获取对每个元素的引用。
例如,当重写适配器的 getView() 方法时,前几行中的一行总是类似于以下内容:
View rootView = inflater.inflate(R.layout.fragmenta, container, false);
EditText edittext = (EditText) rootView.findViewById(R.id.input_user_name);
Button button = (Button) rootView.findViewById(R.id.show_user_name);
TextView textview = (TextView) rootView.findViewById(R.id.display_user_name);
每个布局都重复这种做法 inflation 并称我懒惰,但我正在寻找一种可能通过 Eclipse 插件自动执行此过程的方法。如果插件能够获取布局文件,提取所有具有 android:id 属性的元素,然后生成上面的 java 代码,那就太好了。
插件将获取文件 'fragmenta.xml':
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/input_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/show_user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show user name" />
<TextView
android:id="@+id/display_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
并为 getView() 方法生成一些起始代码:
View rootView = inflater.inflate(R.layout.fragmenta, container, false);
EditText edittext = (EditText) rootView.findViewById(R.id.input_user_name);
Button button = (Button) rootView.findViewById(R.id.show_user_name);
TextView textview = (TextView) rootView.findViewById(R.id.display_user_name);
我相信这个插件对创建其他视图很有用,例如Activity -> onCreate(),片段 -> onCreateView(),适配器 -> getView()。
有这样的插件吗?
感谢您提供任何信息