页面跳转(无结果返回值)(内部监听类事件)

activity就是一个新的布局页面,MainActivity就是继承Activity显示在我们手机的页面,初学的我们都是在一个页面上做文章,但是学过一段时间后,页面已经远远不能满足我们了,页面跳转就是我们新建二个FActivitty和SActivity之间相互跳转,都是新建一个类,继承Activity,创建布局
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
;在我们新建的类之下创建可视化布局factivity.xml文件,在类里面引入我们的xlm文件 setContentView(R.layout.factivity);,这样我们在xlm文件布局之后就可以显示在手机页面上了,但是需要注意的是每当我们新建个类,就要在Androidmainfest里面注册。
有 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
标签的类就有优先显示在手机页面的权利。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.wuzuo.app2">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
        </activity>
        <activity android:name=".FActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SActivity">
        </activity>
    </application>

</manifest>

FActivity.java

package com.example.wuzuo.app2;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * Created by wuzuo on 2016/7/21.
 */
public class FActivity extends Activity {
    private Button button;
    private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.factivity);
        context=this;
        button= (Button) findViewById(R.id.button1_first);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,SActivity.class);
                startActivity(intent);
            }
        });
    }
}

SActivity.java

package com.example.wuzuo.app2;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * Created by wuzuo on 2016/7/21.
 */
public class SActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sactivity);

            }


}

factivity.xlm

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="第一种启动方式"
        android:id="@+id/button1_first" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="第二种启动方式"
        android:id="@+id/button2_second" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="把第二个页面回传的数据显示出来"
        android:id="@+id/textView1"
         />
</LinearLayout>

sactivity.xlm

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button1" />
</LinearLayout>

点击第一个按钮


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值