XML layout to Java code converter

android, java, xml

Solution

Is there any way to have access to those java codes (layout in java)?

There are no such "codes". You are welcome to examine the source to `LayoutInflater`, which, as you will see, looks substantially different than what you envision.

is there any converters I can find?

Asking for off-site resources is considered off-topic for Stack Overflow. For the record, I am not aware of any, and I'd be stunned if somebody spent their time on it.

It would take a very long time to convert it line by line.

Then write it in Java in the first place. Or, use the XML layout resources directly.

I'm working on a project where it will be much easier to work with Java code rather than XML

While I cannot rule out this possibility, it would be rather surprising.

Problem

I know that in Android all XML layout files are converted to Java code on compilation. Is there any way to have access to those java codes (layout in java)? Or if there isn't a way, is there any converters I can find? -- For example: XML layout: ``` <TextView android:layout_width="50px"> </TextView> ``` Java code: ``` TextView textview = new TextView(); textview.setWidth(50); ``` -- As you can see, this is just a simple example, however, layouts are usually much longer. It would take a very long time to convert it line by line. Any suggestions?

Original source