I am learning android development. But I am stucked that ui element don't show in my app's second activity. When loaded.
我正在学习android开发。但我被困在ui元素没有显示在我的应用程序的第二个活动中。加载时
I am using AIDE in my android mobile.
我在Android手机中使用AIDE。
Please take a look at the codes I used up.
请看看我用过的代码。
Main.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:gravity="center"
android:orientation="vertical" >
<TextView
android:textSize="30dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MSQ CORP"
/>
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/newpage"
android:text="New Page"
/>
</LinearLayout>
MainActivity.java
package com.mycompany.msqcorp;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import android.view.View. *;
import android.widget.Button.*;
import android.content.Intent. *;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button a = (Button) findViewById(R.id.newpage);
a.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, secondActivity.class);
startActivity(intent);
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.msqcorp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:label="@string/app_name"
android:name=".MainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="secondActivity"
android:label="New Page"
/>
</application>
</manifest>
second.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:gravity="center"
android:orientation="vertical" >
<TextView
android:textSize="10dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Registeration Form"
android:padding="10dp"
android:id="@+id/text1"
/>
<TextView
android:textSize="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Full Name : "
android:id="@+id/text2"
/>
<EditText
android:textSize="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your Full Name"
android:id="@+id/text3"
/>
</LinearLayout>
SecondActivity.java
package com.mycompany.msqcorp;
import android.system.*;
import android.app. *;
import android.os.*;
import android.view.View. *;
import android.content. *;
import android.test.*;
import android.widget.*;
public class secondActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
// TODO: Implement this method
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}
}
When I run the app, it shows the first screen properly with buttons and text view
当我运行应用程序时,它会使用按钮和文本视图正确显示第一个屏幕
But when loaded next page on button press it shows blank screen. Please help.
但是当按下按钮的下一页时,它会显示空白屏幕。请帮忙。
3 个解决方案
#1
0
use "protected void onCreate(Bundle savedInstanceState)" method instead of "public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)"
使用“protected void onCreate(Bundle savedInstanceState)”方法而不是“public void onCreate(Bundle savedInstanceState,PersistableBundle persistentState)”
#2
0
<activity
android:name="secondActivity"
android:label="New Page"
/>
change this code and try
更改此代码并尝试
<activity
android:name=".secondActivity"
android:label="New Page"
/>
#3
0
You are missing a . (dot) in front of activity declaration in manifest for second activity.
你错过了。 (点)在第二个活动的清单中的活动声明前面。
<activity
android:name="secondActivity"
android:label="New Page"
/>
it should be
它应该是
<activity
android:name=".secondActivity"
android:label="New Page"
/>
Edit: For you second activity try to change onCreate method to
编辑:对于您的第二个活动尝试将onCreate方法更改为
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO: Implement this method
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}
Check if it helps
检查是否有帮助
#1
0
use "protected void onCreate(Bundle savedInstanceState)" method instead of "public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)"
使用“protected void onCreate(Bundle savedInstanceState)”方法而不是“public void onCreate(Bundle savedInstanceState,PersistableBundle persistentState)”
#2
0
<activity
android:name="secondActivity"
android:label="New Page"
/>
change this code and try
更改此代码并尝试
<activity
android:name=".secondActivity"
android:label="New Page"
/>
#3
0
You are missing a . (dot) in front of activity declaration in manifest for second activity.
你错过了。 (点)在第二个活动的清单中的活动声明前面。
<activity
android:name="secondActivity"
android:label="New Page"
/>
it should be
它应该是
<activity
android:name=".secondActivity"
android:label="New Page"
/>
Edit: For you second activity try to change onCreate method to
编辑:对于您的第二个活动尝试将onCreate方法更改为
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO: Implement this method
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}
Check if it helps
检查是否有帮助