I choose my own custom class that implements the Parcelable Interface . since for me such cursors as CrossProcessCursor are completely unknown .
Inside my own ParcelableRow, I just implement a HashMap object . In order to no longer worry about the number of rows or columns, I just map the cursor to my own ParcelableRow object. here is the mi code:
public class ParcelableRow implements Parcelable {
private HashMap<String, String> colsMap;
public static final Parcelable.Creator<ParcelableRow> CREATOR
= new Parcelable.Creator<ParcelableRow>() {
@Override
public ParcelableRow createFromParcel(Parcel source) {
return new ParcelableRow(source);
}
@Override
public ParcelableRow[] newArray(int size) {
return new ParcelableRow[size];
}
};
public ParcelableRow(Parcel in) {
colsMap = new HashMap<String, String>();
readFromParcel(in);
}
public ParcelableRow() {
colsMap = new HashMap<String, String>();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
for(String key: colsMap.keySet()){
dest.writeString(key);
dest.writeString(colsMap.get(key));
}
}
public void readFromParcel(Parcel parcel) {
int limit = parcel.dataSize();
parcel.setDataPosition(0);
for(int i = 0; i < limit; i++){
colsMap.put(parcel.readString(), parcel.readString());
}
}
public void addNewCol(String colName, String colValue){
colsMap.put(colName, colValue);
}
public String getColumnValue(String colName){
return colsMap.get(colName);
}
} Thanks @CommonsWare for giving me the key. thumbs up!.
I hope this can be useful to someone, I just spend a few days trying to find something that can satisfy my needs. here are some code examples that I used. welcome to welcome.
, .
!