Activity 间传递对象, 采用Parcelable. 例子如下:
public class FormatEntity implements Parcelable {
public String mAccount;
public String mCode;
public int limitAmount;
public String imeis;
public PrivateFormatEntity() {
super();
}
public PrivateFormatEntity(Parcel source) {
mAccount = source.readString();
mCode = source.readString();
limitAmount = source.readInt();
imeis = source.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mAccount);
dest.writeString(mCode);
dest.writeInt(limitAmount);
dest.writeString(imeis);
}
public static final Parcelable.Creator<PrivateFormatEntity> CREATOR = new Creator<PrivateFormatEntity>() {
@Override
public PrivateFormatEntity[] newArray(int size) {
return new PrivateFormatEntity[size];
}
@Override
public PrivateFormatEntity createFromParcel(Parcel source) {
return new PrivateFormatEntity(source);
}
};
}
发送:
FormatEntity youFormat = new FormatEntity();
it.putExtra("yourname", youFormat);
获取:
it.getParcelableExtra("yourname");
在android里面除了使用gallery控件以外,经常使用viewflipper来实现类似的效果,其实viewflipper还能够把一些button,view之类的控件也组织起来进行类似的展示
首先在布局文件里定义:
<ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" > </ViewFlipper>
核心代码:
LinearLayout layout1 = new LinearLayout(this); LinearLayout layout2 = new LinearLayout(this); LinearLayout.LayoutParams lp0 = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1); material m[] = material.values(); for (int i = 0; i < m.length; i++) { Button btn = new Button(this); btn.setText(m[i].toString()); btn.setTag(m[i]); btn.setOnClickListener(listener); if (i <= 3) layout1.addView(btn, lp0); else layout2.addView(btn, lp0); } flipper.addView(layout1); flipper.addView(layout2); flipper.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left)); flipper.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
http://www.cmd100.com/bbs/thread-6202-1-1.html