zoukankan      html  css  js  c++  java
  • intent参数的回传

    1.

    public class MainActivity extends Activity {
        private EditText editText1, editText2, editText3;
        private Button button;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            button = (Button) this.findViewById(R.id.button1);
            editText1 = (EditText) this.findViewById(R.id.editText1);
            editText2 = (EditText) this.findViewById(R.id.editText2);
            editText3 = (EditText) this.findViewById(R.id.editText3);
            button.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(MainActivity.this,
                            NextActivity.class);
                    String a = editText1.getText().toString().trim();
                    String b = editText2.getText().toString().trim();
                    intent.putExtra("message", a + "+" + b + "=" + "?");
                    startActivityForResult(intent, 1000);
                }
            });
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);
            if(requestCode==1000&&resultCode==1001){
                editText3.setText(data.getStringExtra("result"));
            }
        }

    2.

    protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.next);
            button=(Button)this.findViewById(R.id.button1);
            textView=(TextView)this.findViewById(R.id.textView1);
            editText=(EditText)this.findViewById(R.id.editText1);
            Intent intent=getIntent();
            String message=intent.getStringExtra("message");
            textView.setText(message);
            button.setOnClickListener(new View.OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    String result=editText.getText().toString().trim();
                    Intent intent=new Intent();
                    intent.putExtra("result", result);
                    //参数回传
                    setResult(1001, intent);
                    finish();
                }
            });
        }

    说明:用startActivityForResult(intent, 1000);启动intent ,重写onActivityResult方法,在跳转的activity中用setResult(1001, intent);返回,并finish()结束

  • 相关阅读:
    gdb段错误
    gdb断点
    init.d详解
    asp.net中的服务器端控件 textbox 设为只读属性后无法获取 javascript给其赋的值
    关于“金点子”征集通知
    Notepad++ SQL Assistant
    IoC Container Benchmark Unity, Windsor, StructureMap and Spring.NET
    如何判断个人电脑是多少位(32位?还是64位系统)
    批量执行SQL文件
    SQL Server 2005 dev 开发板 版本说明
  • 原文地址:https://www.cnblogs.com/ltflike/p/3995860.html
Copyright © 2011-2022 走看看