Android带返回值的窗口跳转

1、AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fish.helloworld"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Receive"
            android:label="@string/title_activity_receive" >
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Send"
            android:label="@string/title_activity_send" >
        </activity>
    </application>

</manifest>

 

2、Receive

package com.fish.helloworld;

import com.fish.helloworld.Forwarding.backButton_OnClickListener;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Receive extends Activity {

    private backButton_OnClickListener backButtonListener = new backButton_OnClickListener();
    private TextView m_TextView;

    
    static final private int GET_CODE = 0;
    
    class backButton_OnClickListener implements OnClickListener{
        public void onClick(View v){
            Intent intent = new Intent(Receive.this, Send.class);
            startActivityForResult(intent, GET_CODE);
            
        }
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.receive_result);
        
        final Button backButton = (Button)findViewById(R.id.button1);
        backButton.setOnClickListener(backButtonListener);
        
         m_TextView = (TextView)findViewById(R.id.textView1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        if(requestCode == GET_CODE){
            String text  = "";
            if(resultCode == RESULT_CANCELED){
                
                text = "Corkey";
            }else{
                
                text = "Violet";
            }
            m_TextView.setText(text);
        }
        
    }
    
}

 

3、Send

package com.fish.helloworld;

import com.fish.helloworld.Receive.backButton_OnClickListener;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Send extends Activity {

    private backButton_OnClickListener backButtonListener = new backButton_OnClickListener();
    private backButton_OnClickListener2 backButtonListener2 = new backButton_OnClickListener2();
    
    
    class backButton_OnClickListener implements OnClickListener{
        public void onClick(View v){
            setResult(RESULT_OK, (new Intent().setAction("Corkey!")));
            finish();
        }
    }
    class backButton_OnClickListener2 implements OnClickListener{
        public void onClick(View v){
            setResult(RESULT_CANCELED, (new Intent().setAction("Violet!")));
            finish();
        }
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.send_result);
        

        final Button backButton = (Button)findViewById(R.id.button1);
        backButton.setOnClickListener(backButtonListener);
        
        final Button backButton2 = (Button)findViewById(R.id.button2);
        backButton2.setOnClickListener(backButtonListener2);
    }

}

 

posted on 2014-07-30 23:42  daixinet.com 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/sshoub/p/3879569.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值