【问题标题】:Automatically Generating java code for xml layout in Eclipse在 Eclipse 中为 xml 布局自动生成 java 代码
【发布时间】:2015-04-02 08:48:32
【问题描述】:

当我们做initializion of views 时,我有一个想法来摆脱一些编码。 当我们在 android 中创建 xml layout 时。在该运动中,同名class 是用UpperCase Letters 创建的,并带有许可对话。当我创建带有 id 的视图时。它应该自动创建视图并初始化它们。

例如

关闭.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

 <Button
   android:id="@+id/closeBtn"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@drawable/close_img" />

 <TextView
   android:id="@+id/closeText"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="Testing Text" />
</LinearLayout>

而且应该是自动生成的java代码。

public class Close extends Activity
{

  TextView CloseText;

  Button CloseBtn;

   @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.activity_main);

        CloseText = (TextView)findViewById(R.id.closeText);

        CloseBtn = (Button)findViewById(R.id.closeBtn);
     }
}

我可以阅读 xml 并按照我解释的那样做其他事情。但是我怎么能把这个模块添加到 eclipse 中,我怎么能创建一个在 eclipse 中一直在后台工作的服务。

建议我如何将此模块(插件)添加到 Eclipse,我将使用 JAXB to generate Java Objects from XML document。有没有更好的选择。

【问题讨论】:

  • 1.off-topic as 要求我们推荐或查找书籍、工具、软件库、教程或其他场外资源的问题对于 Stack Overflow 来说是题外话 2. 已经回答(我很确定我上周看到了类似的问题)... 3. 有很多基于注释的库
  • 那么你为什么不分享一个@Selvin。这意味着如果您没有答案,那么请投反对票。以及我要求推荐一本书、软件等的地方。

标签: android xml class xml-parsing jaxb


【解决方案1】:

在这个网站上,我发现只需粘贴 xml,您就可以为活动类准备好您的 java 代码。 i had attached the link

【讨论】:

  • 请注意 link-only answers 是不鼓励的,所以答案应该是寻找解决方案的终点(而不是另一个参考中途停留,随着时间的推移往往会变得陈旧)。请考虑在此处添加独立的概要,并保留链接作为参考。
猜你喜欢
  • 2012-08-07
  • 2011-05-14
  • 2019-12-19
  • 2011-04-07
  • 2011-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多