效果:
想看實例的,感興趣的可以看之前的一篇文章
Android ViewPager Fragment實現選項卡
部分關鍵代碼:
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHByZSBjbGFzcz0="brush:java;">public class SerializeActivity extends Activity implements Serializable {
Button btnlist, btnParcelable, btnSerialze;
private final String TAG = "SerializeActivity";
public final static String LIST_KEY = "ArrayList";
public final static String PAR_KEY = "parcelable";
public final static String SER_KEY = "serializable";
private static final long serialVersionUID = 1L;
private ArrayList m_list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_serialize);
initView();
initlist();
}
/*
* 初始化視圖
*/
public void initView() {
btnlist = (Button) findViewById(R.id.btnlist);
btnParcelable = (Button) findViewById(R.id.btnParcelable);
btnSerialze = (Button) findViewById(R.id.btnSerialze);
btnlist.setOnClickListener(btnlistener);
btnParcelable.setOnClickListener(btnlistener);
btnSerialze.setOnClickListener(btnlistener);
}
public void initlist() {
m_list = new ArrayList();
m_list.add("www.88ios.com");
m_list.add("Android移動開發");
m_list.add("IOS開發入門");
}
/*
* 按鈕點擊事件
*/
OnClickListener btnlistener = new OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnlist:
intentList();
break;
case R.id.btnParcelable:
intentParcelabe();
break;
case R.id.btnSerialze:
intentShowSer();
break;
}
}
};
/*
*
*/
public void intentList() {
Intent list_intent = new Intent();
list_intent.putStringArrayListExtra(LIST_KEY, m_list);
list_intent.setClass(SerializeActivity.this, ShowInfo.class);
startActivity(list_intent);
}
/*
*
*/
public void intentParcelabe() {
Student m_Student = new Student();
m_Student.setName("88ios.com");
m_Student.setAge(25);
m_Student.setSex("男");
Intent p_Intent = new Intent(SerializeActivity.this,
ShowParcelabe.class);
Bundle mBundle = new Bundle();
mBundle.putParcelable(PAR_KEY, m_Student);
p_Intent.putExtras(mBundle);
startActivity(p_Intent);
}
/*
*
*/
public void intentShowSer() {
final SerializableMap myMap = new SerializableMap();
List