为何无法显示第二个 Activity 里面的控件?请高手指点,谢谢!strings.xml文件内容
<resources> <string name="app_name">Hello</string>
<string name="hello_world">您好,世界,我的第一个安卓应用程序!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_my_program">MyProgram</string></resources>activity_my_program.xml 文件内容
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/Text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/><Button
android:id="@+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/Text1"
android:layout_marginTop="88dp" /></RelativeLayout>
MyProgram.java 内容
package com.example.hello;import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;public class MyProgram extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_program);
TextView myText=(TextView)findViewById(R.id.Text1);
Button mybutton=(Button)findViewById(R.id.Button1);
myText.setText("我的第一个安卓应用程序");
mybutton.setText("我的第一个安卓按钮"+"\n"+"Text");
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_my_program, menu);
return true;
}
}test.xml内容 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </LinearLayout>test.java内容
package com.example.hello;import android.app.Activity;
import android.os.Bundle;public class test extends Activity{ @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}}AndroidManifest.xml内容
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hello"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="15" /> <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".test"
android:label="@string/title_activity_my_program" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application></manifest>android
<resources> <string name="app_name">Hello</string>
<string name="hello_world">您好,世界,我的第一个安卓应用程序!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_my_program">MyProgram</string></resources>activity_my_program.xml 文件内容
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/Text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/><Button
android:id="@+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/Text1"
android:layout_marginTop="88dp" /></RelativeLayout>
MyProgram.java 内容
package com.example.hello;import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;public class MyProgram extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_program);
TextView myText=(TextView)findViewById(R.id.Text1);
Button mybutton=(Button)findViewById(R.id.Button1);
myText.setText("我的第一个安卓应用程序");
mybutton.setText("我的第一个安卓按钮"+"\n"+"Text");
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_my_program, menu);
return true;
}
}test.xml内容 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </LinearLayout>test.java内容
package com.example.hello;import android.app.Activity;
import android.os.Bundle;public class test extends Activity{ @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}}AndroidManifest.xml内容
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hello"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="15" /> <application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".test"
android:label="@string/title_activity_my_program" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application></manifest>android
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货