Bonjour,
J'ai besoin d'aide pour utiliser Parcelable dans ma class objet, j'ai un petit problème pour parser tout mes attributs étant donner que j'ai certains type qui ne sont pas primitif (donc là commence la complexité).
En effet j'ai tout ces types d'attribut ci dans ma classe Objet (ou j'ai tout mes accesseurs..):
Comme vous pouvez le voir j'ai un type qui est lui-même un objet (position) de type PositionBean.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 private int number; private String name; private String address; private PositionBean position; private boolean banking; private boolean bonus; private String status; private String contract_name; private int bike_stands; private int available_bike_stands; private int available_bikes; private long last_update;
Voilà comment est construit mon PositionBean:
J'ai donc essayé dans mon Parcel, tant bien que mal de faire ça:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public static class PositionBean { /** * lat : 47.212108463141774 * lng : -1.553049129320471 */ private double lat; private double lng; public double getLat() { return lat; } public void setLat(double lat) { this.lat = lat; } public double getLng() { return lng; } public void setLng(double lng) { this.lng = lng; } }
Mais ça ne passe pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 this.number = parcel.readInt(); this.name = parcel.readString(); this.address = parcel.readString(); this.position = parcel.readDouble()==PositionBean.getLat().PositionBean.getLng(); this.banking = parcel.readByte()==1?true:false; this.bonus = parcel.readByte()==1?true:false; this.status = parcel.readString(); this.contract_name = parcel.readString(); this.bike_stands = parcel.readInt(); this.available_bike_stands = parcel.readInt(); this.available_bikes = parcel.readInt(); this.last_update = parcel.readLong();
Pour le coup dans mon "writeToParcel" non plus.
J'ai cherchais mais je ne trouve pas comment je peux traiter mon objet PositionBean.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 parcel.writeInt(this.number); parcel.writeString(this.name); parcel.writeString(this.address); parcel.writeByte(this.position)==PositionBean.getLat().PositionBean.getLng(); parcel.writeByte(this.banking)==1?true:false; parcel.writeByte(this.bonus)==1?true:false; parcel.writeString(this.status); parcel.writeString(this.contract_name); parcel.writeInt(this.bike_stands); parcel.writeInt(this.available_bike_stands); parcel.writeInt(this.available_bikes); parcel.writeLong(this.last_update);
Ni mes deux Boolean.
Partager