I want to have a function where I just send the XML Android layout and the function returns me the java code of the activity for example I call the function like this:
String Layout = "<LinearLayout xmlns:android="[login to view URL]"
xmlns:tools="[login to view URL]"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/lbFullName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Full Name:"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="20dip"/>
<EditText android:id="@+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:layout_marginBottom="20dip"/>
<TextView
android:id="@+id/lbEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Email:"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"/>
<EditText android:id="@+id/txtEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:layout_marginBottom="20dip"/>
<Button android:id="@+id/btnRegister"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Register"
android:layout_margin="10dip"/>
</LinearLayout>
";
createActivityFromLayout(Layout, activityName);
Returns me:
"import [login to view URL];
import [login to view URL];
import [login to view URL];
import [login to view URL];
import [login to view URL];
import [login to view URL];
public class Test extends Activity {
private TextView lbFullName;
private EditText txtName;
private TextView lbEmail;
private EditText txtEmail;
private Button btnRegister;
@Override
public void onCreate(Bundle savedInstanceState) {
[login to view URL](savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
*
*/
private void findViews() {
lbFullName = (TextView)findViewById( [login to view URL] );
txtName = (EditText)findViewById( [login to view URL] );
lbEmail = (TextView)findViewById( [login to view URL] );
txtEmail = (EditText)findViewById( [login to view URL] );
btnRegister = (Button)findViewById( [login to view URL] );
[login to view URL]( this );
}
/**
*
*/
@Override
public void onClick(View v) {
if ( v == btnRegister ) {
// Handle clicks for btnRegister
}
}
}"
This javascript does almost the same
[login to view URL]
It is open source but in javascript and I need it in Java.
[login to view URL]
Elements of the XML could be>
"AbsoluteLayout","AdapterViewFlipper","AnalogClock","AutoCompleteTextView","Button","CalendarView","CheckBox","CheckedTextView","Chronometer","DatePicker","DialerFilter","DigitalClock","EditText","ExpandableListView","FrameLayout","Gallery","GestureOverlayView","GridLayout","GridView","HorizontalScrollView","ImageButton","ImageSwitcher","ImageView","LinearLayout","MediaController","MultiAutoCompleteTextView","NumberPicker","ProgressBar","QuickContactBadge","RadioButton","RadioGroup","RatingBar","RelativeLayout","ScrollView","SearchView","SeekBar","SlidingDrawer","Space","Spinner","StackView","SurfaceView","Switch","TabHost","TableLayout","TableRow","TabWidget","TextSwitcher","TextureView","TextView","TimePicker","ToggleButton","TwoLineListItem","VerticalLinearLayout","ViewAnimator","ViewFlipper","ViewStub","ViewSwitcher","WebView","ZoomButton","ZoomControls".
Validations>
The name of element's must be unique.
The function must provide all imports.
Function must be done in a class in an static way to just call it