Intent 传递类对象的方法二 传值和取值
来源:互联网 发布:万维网中文域名到期 编辑:程序博客网 时间:2024/06/11 03:58
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button android:id="@+id/btn_01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Serilizable"/>
<Button android:id="@+id/btn_02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Parcelable"/>
</LinearLayout>
MianActivity.java
package cn.edu.wtu;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class IntentDemo extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn_01 = (Button) findViewById(R.id.btn_01);
Button btn_02 = (Button) findViewById(R.id.btn_02);
btn_01.setOnClickListener(this);
btn_02.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.btn_01:{
Intent intent = new Intent(this,PersonView.class);
Person mPerson = new Person();
mPerson.setAge(20);
mPerson.setName("moon");
Bundle bundle = new Bundle();
bundle.putSerializable("person", mPerson);
intent.putExtras(bundle);
startActivity(intent);
break;
}
case R.id.btn_02:{
Intent intent = new Intent(this,BookView.class);
Book book = new Book();
book.setName("manmonth");
book.setTime("1975");
book.setAuthor("Brooks");
Bundle bundle = new Bundle();
bundle.putParcelable("book", book);
intent.putExtras(bundle);
startActivity(intent);
break;
}
}
}
}
取值
public class PersonView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
Person person = (Person)getIntent().getSerializableExtra("person");
text.setText("name:"+person.getName()+"/nage:"+person.getAge()+"/n");
setContentView(text);
}
}
取值
public class BookView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
Book book = (Book) getIntent().getParcelableExtra("book");
text.setText("name:"+book.getName()+"/nautor:"+book.getAuthor()+"/ntime:"+book.getTime());
setContentView(text);
}
}
- Intent 传递类对象的方法二 传值和取值
- Android中Intent传递类对象的方法二(Parcelable)
- Android中Intent传递对象的两种方法------Serializable传值和Parcelable传值
- Intent 传递类对象的方法一
- Intent传递类对象值
- Android Intent传值和Activity之间对象列表传递
- Intent传递对象的两种方法Serializable 和 Parcelable
- Android中Intent传递类对象的方法一(Serializable)
- intent传递对象的两种方法
- intent传递对象的两种方法
- intent传递对象的两种方法
- Intent传递对象的两种方法
- 通过Intent传递对象的另类方法
- Intent 传递对象的两种方法
- Android对象序列化(二)-----Intent传递对象的两种方法(Serializable,Parcelable)
- Java面向对象-方法的值传递和引用传递
- Intent 传递类对象
- intent传递类对象
- 拆分为连续正整数之和
- Android中屏幕的方向
- 移动端 根据屏幕宽度来等比调解高度的大小
- 字典树(讲解+模版)
- struts2 中英文切换
- Intent 传递类对象的方法二 传值和取值
- iOS开发--音频播放、录音、视频播放、拍照、视频录制(转载)
- SQL查询相关技术-3.更改显示报表行项目
- android 自定义含有滚动选择器的对话框
- C++ Builder中导入Excel表格数据
- 在eclipse中图形化添加maven项目jar包
- Spark快速入门指南
- 小Ai成功预测我是歌手依靠的是什么
- 网易 比较重量