android activity Intent 传值 传对象,android开发框架开源登录界面

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

public class MainActivity extends Activity {

EditText et_cont

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

浏览器打开:qq.cn.hn/FTe 免费领取

ent;

Button btn;

EditText et_name, et_sex;

Button btn_object;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// 传值

et_content = (EditText) findViewById(R.id.et_content);

btn = (Button) findViewById(R.id.btn);

btn.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

Intent i = new Intent(MainActivity.this, BActivity.class);

i.putExtra(“content”, et_content.getText().toString());

startActivity(i);

}

});

// 传对象

et_name = (EditText) findViewById(R.id.et_name);

et_sex = (EditText) findViewById(R.id.et_sex);

btn_object = (Button) findViewById(R.id.btn_object);

btn_object.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

MyInfoBean mib = new MyInfoBean(""

  • et_name.getText().toString(), “”

  • et_sex.getText().toString());

Bundle bd = new Bundle();

bd.putSerializable(“mib”, mib);

Intent i = new Intent(MainActivity.this, OActivity.class);

i.putExtras(bd);

startActivity(i);

}

});

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

}

2.传值接收 B.java


package com.yqy.yqy_intenttest;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.widget.TextView;

public class BActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_b);

//接收值

String content = getIntent().getStringExtra(“content”);

TextView tv_show = (TextView) findViewById(R.id.tv_show);

tv_show.setText(content);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.b, menu);

return true;

}

}

3.传递对象  实体类  o。java


package com.yqy.yqy_intenttest;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.widget.TextView;

public class OActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_o);

Intent i = getIntent();

Bundle bd = i.getExtras();

MyInfoBean mib = (MyInfoBean) bd.getSerializable(“mib”);

TextView tv_name = (TextView) findViewById(R.id.tv_name);

TextView tv_sex = (TextView) findViewById(R.id.tv_sex);

tv_name.setText(mib.getName());

tv_sex.setText(mib.getSex());

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.o, menu);

return true;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值