0

im new to this coding. but when i create a new layout/activity (i.e a new .xml) shouldn't a new .java file be created as well that corresponding to the new file. like when you create MainActvity.xml for the first time the MainActivty.java is also in the SRC/com.example... folder. so im a little confused.

So what i did was create anther new .xml form file>new> Android XML file . created fine but now .java file?

i'm curious about this because when i did my intent code it wouldn't load up the page. im guessing that it wasn't "linked" with the java file or something. (

4

3 回答 3

1

不,它不会自己创建 java 文件。XML 文件可以是其他内容,而不仅仅是活动文件的布局。因此,没有必要为每个 XML 文件都有一个 java 类。

创建新项目时创建的只是为了方便,它假设您将拥有至少一个活动类(JAVA 文件)和一个相应的布局文件(XML)。

于 2013-12-11T06:56:20.617 回答
0

不,没有必要为每个 .xml 文件创建 .java 文件。有时我们将 .xml 文件膨胀到 .java 文件中的现有 .xml 文件中。要显示您的 .xml ,必须在 .java 文件上设置它。

于 2013-12-11T06:58:45.663 回答
0
right click on project->new->class

then add this in new class
public class newclass extends Activity {
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newxml);

}}

and add android name in androidmanifest file
于 2013-12-11T06:59:58.137 回答