我看不到取得双布尔数组通过传递到另一个活动。我用putExtra,当我找回它,并把它转换为布尔[] [] ,它指出,它不能施放和崩溃。布尔[]然而工作。
I can't see to get a double boolean array to pass through to the another activity. I use putExtra and when I retrieve it and cast it to boolean[][], it states that it can not cast and crashes. Boolean[] works however.
我如何去传递一个布尔[] [] 活动的?
How would I go about passing a boolean[][] between activities?
推荐答案如果你绝对需要一个布尔[] [](而不能只用一台布尔[]数组传递给Parcel.writeBooleanArray做到这一点()) ,那么正式的方式做,这是包装在一个Parcelable类,做编组/解组那里。
If you absolutely need a boolean[][] (and can't do this with just a flat boolean[] array passed to Parcel.writeBooleanArray()), then the formal way to do this is to wrap it in a Parcelable class and do the marshalling/unmarshalling there.
所以肯定会有一些问题,我会勾画出code,虽然这不是测试。
I'll sketch out the code, though this is not tested so there are certainly to be some issues.
public class BooleanArrayArray implements Parcelable { private final boolean[][] mArray; public BooleanArrayArray(boolean[][] array) { mArray = array; } private BooleanArrayArray(Parcelable in) { boolean[][] array; final int N = in.readInt(); array = new boolean[][N]; for (int i=0; i<N; i++) { array[i] = in.createBooleanArray(); } mArray = array; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel out, int flags) { final int N = mArray.length; out.writeInt(N); for (int i=0; i<N; i++) { out.writeBooleanArray(mArray[i]); } } public static final Parcelable.Creator<BooleanArrayArray> CREATOR = new Parcelable.Creator<BooleanArrayArray>() { public BooleanArrayArraycreateFromParcel(Parcel in) { return new BooleanArrayArray(in); } public BooleanArrayArray[] newArray(int size) { return new BooleanArrayArray[size]; } }; }更多推荐
如何通过活动之间的双阵列(布尔[] [])?
发布评论