在Eclipse中向Android项目添加活动的最佳方式是什么?

时间:2023-01-17 14:16:24

When adding an activity to an existing Android project, I manually create a new class - is that the best / preferred way? How do others handle that?

在现有的Android项目中添加活动时,我手动创建一个新类——这是最好的/首选的方法吗?其他人是怎么处理的?

8 个解决方案

#1


380  

You can use the "New Class" dialog, but that leaves other steps you need to do by hand (e.g. adding an entry to the manifest file). If you want those steps to be automated, you can create the activity via the manifest editor like this:

您可以使用“New Class”对话框,但这将留下您需要手动执行的其他步骤(例如,向清单文件添加一个条目)。如果您希望自动化这些步骤,您可以通过清单编辑器创建活动,如下所示:

  1. Double click on AndroidManifest.xml in the package explorer.
  2. 双击AndroidManifest。包浏览器中的xml。
  3. Click on the "Application" tab of the manifest editor
  4. 单击清单编辑器的“应用程序”选项卡
  5. Click on "Add.." under the "Application Nodes" heading (bottom left of the screen)
  6. 单击“应用程序节点”标题下的“Add.. .”(屏幕左下角)
  7. Choose Activity from the list in the dialog that pops up (if you have the option, you want to create a new top-level element)
  8. 从弹出的对话框中选择活动(如果您有这个选项,您需要创建一个新的*元素)
  9. Click on the "Name*" link under the "Attributes for" header (bottom right of the window) to create a class for the new activity.
  10. 单击“属性”头(窗口右下角)下的“Name*”链接,为新活动创建一个类。

When you click Finish from the new class dialog, it'll take you to your new activity class so you can start coding.

当您从新的类对话框中单击Finish时,它将带您到您的新activity类,这样您就可以开始编写代码了。

Five steps might seem a lot, but I'm just trying to be extra detailed here so that it's clear. It's pretty quick when you actually do it.

五个步骤看起来可能很多,但我只是想在这里做得更详细一些,这样就清楚了。当你真正去做的时候,它是非常快的。

#2


88  

It is now much easier to do this in Eclipse now. Just right click on the package that will contain your new activity. New -> Other -> (Under Android tab) Android Activity.

现在在Eclipse中这样做要容易得多。只需右键单击包含新活动的包。新->其他->(在Android选项卡下)Android活动。

And that's all. Your new activity is automatically added to the manifest file as well.

这是所有。您的新活动也会自动添加到清单文件中。

#3


15  

An easy method suggested by Google Android Developer Community.

在Eclipse中向Android项目添加活动的最佳方式是什么?

#4


4  

I just use the "New Class" dialog in Eclipse and set the base class as Activity. I'm not aware of any other way to do this. What other method would you expect to be available?

我只是在Eclipse中使用“New Class”对话框,并将基类设置为活动。我不知道还有别的办法。你还希望有什么其他的方法?

#5


3  

The R.* classes are generated dynamically. I leave the "Build automatically" option on in the Project menu so that mine R.* classes are always up-to-date.

R。*类是动态生成的。我把“自动构建”选项留在项目菜单上,这样我的R。*课程总是最新的。

Additionally, when creating new Activities, I copy and rename old ones, especially if they are similar to the new Activity that I need because Eclipse renames everything for you.

此外,在创建新活动时,我复制并重命名旧活动,特别是如果它们与我需要的新活动类似,因为Eclipse为您重命名了所有内容。

Otherwise, as others have said, the File->New->Class command works well and will build your file for you including templates for required methods based on your class, its inheritance and interfaces.

否则,正如其他人所说的,文件>New->类命令可以很好地工作,并将为您构建文件,包括基于您的类、它的继承和接口的所需方法的模板。

#6


2  

For creating new Activity simply click ctrl+N one window is appear select android then another window is appear give name to that Secondary Activity.Now another Activity is created

要创建新活动,只需单击ctrl+N,其中一个窗口出现,选择android,然后另一个窗口出现,为该次级活动命名。现在创建了另一个活动

#7


1  

There is no tool, that I know of, which is used specifically create activity classes. Just using the 'New Class' option under Eclipse and setting the base class to 'Activity'.

没有工具,我知道,它是专门用来创建活动类的。只需在Eclipse下使用“New Class”选项,并将基类设置为“Activity”。

Thought here is a wizard like tool when creating/editing the xml layout that are used by an activity. To use this tool to create a xml layout use the option under 'New' of 'Android XML File'. This tool will allow you to create some of the basic layout of the view.

在创建/编辑活动使用的xml布局时,这里有一个类似向导的工具。要使用此工具创建xml布局,请使用“Android xml文件”的“New”选项。该工具将允许您创建视图的一些基本布局。

#8


0  

I have create a eclipse plugin to create activity in one click .

我创建了一个eclipse插件,在单击时创建活动。

Just download the Plugin from https://docs.google.com/file/d/0B63U_IjxUP_GMkdYZzc1Y3lEM1U/edit?usp=sharing

只需从https://docs.google.com/file/d/0b63u_ijxup_gmkdyz1y3lem1u/edit?

Paste the plugin in the dropins folder in Eclipse and restart eclipse

在Eclipse的dropins文件夹中粘贴插件并重新启动Eclipse

For more details please see my blog
http://shareatramachandran.blogspot.in/2013/06/android-activity-plugin-for-eclispe.html

有关更多细节,请参见我的博客http://shareatramachandran.blogspot.in/2013/06/android-activity-plugin For eclispe.html

Need your comment on this if it was helpful...

如果有帮助的话,需要你的评论。

#1


380  

You can use the "New Class" dialog, but that leaves other steps you need to do by hand (e.g. adding an entry to the manifest file). If you want those steps to be automated, you can create the activity via the manifest editor like this:

您可以使用“New Class”对话框,但这将留下您需要手动执行的其他步骤(例如,向清单文件添加一个条目)。如果您希望自动化这些步骤,您可以通过清单编辑器创建活动,如下所示:

  1. Double click on AndroidManifest.xml in the package explorer.
  2. 双击AndroidManifest。包浏览器中的xml。
  3. Click on the "Application" tab of the manifest editor
  4. 单击清单编辑器的“应用程序”选项卡
  5. Click on "Add.." under the "Application Nodes" heading (bottom left of the screen)
  6. 单击“应用程序节点”标题下的“Add.. .”(屏幕左下角)
  7. Choose Activity from the list in the dialog that pops up (if you have the option, you want to create a new top-level element)
  8. 从弹出的对话框中选择活动(如果您有这个选项,您需要创建一个新的*元素)
  9. Click on the "Name*" link under the "Attributes for" header (bottom right of the window) to create a class for the new activity.
  10. 单击“属性”头(窗口右下角)下的“Name*”链接,为新活动创建一个类。

When you click Finish from the new class dialog, it'll take you to your new activity class so you can start coding.

当您从新的类对话框中单击Finish时,它将带您到您的新activity类,这样您就可以开始编写代码了。

Five steps might seem a lot, but I'm just trying to be extra detailed here so that it's clear. It's pretty quick when you actually do it.

五个步骤看起来可能很多,但我只是想在这里做得更详细一些,这样就清楚了。当你真正去做的时候,它是非常快的。

#2


88  

It is now much easier to do this in Eclipse now. Just right click on the package that will contain your new activity. New -> Other -> (Under Android tab) Android Activity.

现在在Eclipse中这样做要容易得多。只需右键单击包含新活动的包。新->其他->(在Android选项卡下)Android活动。

And that's all. Your new activity is automatically added to the manifest file as well.

这是所有。您的新活动也会自动添加到清单文件中。

#3


15  

An easy method suggested by Google Android Developer Community.

在Eclipse中向Android项目添加活动的最佳方式是什么?

#4


4  

I just use the "New Class" dialog in Eclipse and set the base class as Activity. I'm not aware of any other way to do this. What other method would you expect to be available?

我只是在Eclipse中使用“New Class”对话框,并将基类设置为活动。我不知道还有别的办法。你还希望有什么其他的方法?

#5


3  

The R.* classes are generated dynamically. I leave the "Build automatically" option on in the Project menu so that mine R.* classes are always up-to-date.

R。*类是动态生成的。我把“自动构建”选项留在项目菜单上,这样我的R。*课程总是最新的。

Additionally, when creating new Activities, I copy and rename old ones, especially if they are similar to the new Activity that I need because Eclipse renames everything for you.

此外,在创建新活动时,我复制并重命名旧活动,特别是如果它们与我需要的新活动类似,因为Eclipse为您重命名了所有内容。

Otherwise, as others have said, the File->New->Class command works well and will build your file for you including templates for required methods based on your class, its inheritance and interfaces.

否则,正如其他人所说的,文件>New->类命令可以很好地工作,并将为您构建文件,包括基于您的类、它的继承和接口的所需方法的模板。

#6


2  

For creating new Activity simply click ctrl+N one window is appear select android then another window is appear give name to that Secondary Activity.Now another Activity is created

要创建新活动,只需单击ctrl+N,其中一个窗口出现,选择android,然后另一个窗口出现,为该次级活动命名。现在创建了另一个活动

#7


1  

There is no tool, that I know of, which is used specifically create activity classes. Just using the 'New Class' option under Eclipse and setting the base class to 'Activity'.

没有工具,我知道,它是专门用来创建活动类的。只需在Eclipse下使用“New Class”选项,并将基类设置为“Activity”。

Thought here is a wizard like tool when creating/editing the xml layout that are used by an activity. To use this tool to create a xml layout use the option under 'New' of 'Android XML File'. This tool will allow you to create some of the basic layout of the view.

在创建/编辑活动使用的xml布局时,这里有一个类似向导的工具。要使用此工具创建xml布局,请使用“Android xml文件”的“New”选项。该工具将允许您创建视图的一些基本布局。

#8


0  

I have create a eclipse plugin to create activity in one click .

我创建了一个eclipse插件,在单击时创建活动。

Just download the Plugin from https://docs.google.com/file/d/0B63U_IjxUP_GMkdYZzc1Y3lEM1U/edit?usp=sharing

只需从https://docs.google.com/file/d/0b63u_ijxup_gmkdyz1y3lem1u/edit?

Paste the plugin in the dropins folder in Eclipse and restart eclipse

在Eclipse的dropins文件夹中粘贴插件并重新启动Eclipse

For more details please see my blog
http://shareatramachandran.blogspot.in/2013/06/android-activity-plugin-for-eclispe.html

有关更多细节,请参见我的博客http://shareatramachandran.blogspot.in/2013/06/android-activity-plugin For eclispe.html

Need your comment on this if it was helpful...

如果有帮助的话,需要你的评论。