将多个变量值发送到另一个活动 [英] Sending multiple variable values to another activity

查看:80
本文介绍了将多个变量值发送到另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用来将字符串变量的值传输到另一个活动的代码.

So this is the code that I use to transfer the value of a string variable to another activity.

            Intent requestLink = new Intent(Search.this, Results.class);
            requestLink.putExtra("Link", sendLink);
            startActivity(requestLink);

但是,如果我希望传递多个变量,该怎么办.

But what if I wish to transfer more than one variable.

            Intent requestLink = new Intent(Search.this, Results.class);
            requestLink.putExtra("Link", sendLink);
            startActivity(requestLink);


            Intent userSearch = new Intent(Search.this, Results.class);
            userSearch.putExtra("Search", addressInput);
            startActivity(userSearch);

像上面一样,两次使用代码仅会启动两个单独的活动.那么,如何同时传输这些值?

Using the code twice will like the above will only just start two separate activities. So, how can I transfer the values simultaneously?

我还是Android开发和OOP的新手.

I'm still pretty new to Android development and also OOP.

推荐答案

btnlogin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent=new Intent(getBaseContext(),db.class);
             String username=uname.getText().toString();
             String upaswrd=pass.getText().toString();
            // Bundle bundle=new Bundle();

          intent.putExtra(name,username);
          intent.putExtra(paswrd, upaswrd);

          startActivity(intent);
        }
    });


/** Db.class */

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.db);
    Intent intent=getIntent();
    String uname=intent.getStringExtra(Gmail.name);
    String upass=intent.getStringExtra(Gmail.paswrd);
    username=(TextView)findViewById(R.id.u);
    username.setText(uname);
    pass=(TextView)findViewById(R.id.p);
    pass.setText(upass);

}

这篇关于将多个变量值发送到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆