如何更改当前页面,从 activity_main.xml 切换到 pagetwo.xml
How to change current page, switching from activity_main.xml to pagetwo.xml
我无法从一页移动到另一页。
按钮不起作用,如果我按下它什么也不会发生。
你能解释一下为什么吗?
我只想转到 activity_main.xml
到 pagetwo.xml
页,为此我尝试更改 Activity
.
我的页面:
主要活动:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
...
}
}
class open extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i= new Intent("call");
startActivity(i);
}
});
}
}
通话:
public class call extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pagetwo);
}
}
清单:
...
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".call"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter >
<action android:name="android.intent.action.PICK_ACTIVITY"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
pagetwo:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Finally"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</RelativeLayout>
activity_main:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_marginTop="6dp"
android:layout_centerHorizontal="true"
android:text="page two" />
</RelativeLayout>
再见!
您没有正确使用意图。请检查下面的源代码 class open
class open extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i= new Intent(this, call.class);
startActivity(i);
}
});
}
}
像下面这样更改代码并检查
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i= new Intent(MainActivity.class, call.class);
startActivity(i);
}
});
我无法从一页移动到另一页。
按钮不起作用,如果我按下它什么也不会发生。
你能解释一下为什么吗?
我只想转到 activity_main.xml
到 pagetwo.xml
页,为此我尝试更改 Activity
.
我的页面:
主要活动:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
...
}
}
class open extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i= new Intent("call");
startActivity(i);
}
});
}
}
通话:
public class call extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pagetwo);
}
}
清单:
...
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".call"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter >
<action android:name="android.intent.action.PICK_ACTIVITY"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
pagetwo:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Finally"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</RelativeLayout>
activity_main:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_marginTop="6dp"
android:layout_centerHorizontal="true"
android:text="page two" />
</RelativeLayout>
再见!
您没有正确使用意图。请检查下面的源代码 class open
class open extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i= new Intent(this, call.class);
startActivity(i);
}
});
}
}
像下面这样更改代码并检查
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i= new Intent(MainActivity.class, call.class);
startActivity(i);
}
});