I am developing an Android app using Eclipse and I have noticed the creation of the GetView() method is quite time consuming for something I think should be automated, especially when a typical app contains many layouts to be inflated. I don't mean implementing the listeners but rather simply obtaining a reference to each element with an id from the newly inflated layout.
For example when overriding an adaptor's getView() method, one of the first few lines invariably reads similar to the following:
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);
This practice is repeated for every layout inflation and call me lazy but I am looking for a means of automating this process perhaps via an Eclipse plugin. It would be nice for the plugin to take a layout file, extract all elements with an android:id attribute and then generate the above java code.
The plugin will take the file '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>
And generate some starter code for the getView() method:
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);
I am sure this plugin will be useful for other view creation e.g. Activity -> onCreate(), Fragment -> onCreateView(), Adaptor -> getView().
Does such a plugin exist?
Thankyou for any information