简体   繁体   English

如何在我的Android应用程序项目中包括一个新的.java文件?

[英]How to include a new .java file in my Android app project?

I'm sorry, I'm a newbie, and I think that's simple, but I'm discovering the coding with Eclipse so I have this simple question : How to include a new .java file in my Android project ? 抱歉,我是新手,这很简单,但是我发现使用Eclipse进行编码,所以我有一个简单的问题:如何在Android项目中包含新的.java文件?

My words are perhaps inapropriates, and to be more clear, I'm creating an Android application, and I want to include a .java file (located in projectname/src/ ) 我的话可能不恰当,更明确地说,我正在创建一个Android应用程序,并且我想包含一个.java文件(位于projectname / src /中

Actually I have an unique file, MainActivity.java , and my application start fine. 实际上,我有一个唯一的文件MainActivity.java ,我的应用程序正常运行。 I want to include a timer in my application, so I created a new Timer.java file in same folder, but when I start my app, it contain only data from this MainActivity.java file, nothing about my Timer.jar file. 我想在我的应用程序中包含一个计时器,所以我在同一文件夹中创建了一个新的Timer.java文件,但是当我启动应用程序时,它仅包含MainActivity.java文件中的数据,而与Timer.jar文件无关。

So how I must declare the new file in my project ? 那么,如何在项目中声明新文件呢?

you simply add it by right clicking on your src folder 您只需右键单击src文件夹将其添加 在此处输入图片说明

you need to declare it on your AndroidManifest.xml file 您需要在AndroidManifest.xml文件中声明它

    <activity
        android:name=".Timer"
        android:label="@string/title_timer" >
    </activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM