touchingtwist touchingtwist - 2 months ago 5
Android Question

How can i implement this class for new class in Activity?

PostData

public class PostData {
@Expose
private String text;
@Expose
private Point point;
public class Point implements Serializable {
@Expose
private double longitude;
@Expose
private double latitude;
public Point(double longitude, double latitude) {
this.longitude = longitude;
this.latitude = latitude;
}
}
public PostData(String text, Point point) {
this.text = text;
this.point = point;
}
}


I want use it like

PostData postData = new PostData()


so i tried this like

PostData postData = new PostData("nqq", mpoint){
Point mpoint = new PostData.Point("13", "14");
};


But it has something wrong.

Actually i don't know how to deal with
point
class.

Would you let me know example?

How can i use it in right way?

Answer

Rather than using inner class , separate PostData and Point Class

   public class PostData {
        @Expose
        private String text;
        @Expose
        private Point point;

        public PostData(String text, Point point) {
            this.text = text;
            this.point = point;
        }
    }

    public class Point implements Serializable {
        @Expose
        private double longitude;
        @Expose
        private double latitude;
        public Point(double longitude, double latitude) {
            this.longitude = longitude;
            this.latitude = latitude;
        }
    }

And then use like this way

Point point = new Point(13,14);
Postdata postDate = new PostDate("nqq",point);