语言

Menu
Sites
Language
ArrayList that can hold a point

I want to use an arraylist to store points so that I can use the points to draw a Line. I have defined the arraylist as

Tizen::Base::Collection::ArrayListT<Point>* list_points = new Tizen::Base::Collection::ArrayListT<Point>();

I am able to add a point to the points arraylist using the Add method as : list_points->Add(  Point( 20 , 30 ) );

Now suppose say I want to access 10 points in the list_points. How can I do that? I can across a function know as GetAt but basically it returns an Object.

I want the output to be of type Point only so I can do something like Point p = ( get the first Point from list_points ). As I want to draw a line and DrawLine function takes two Points as an argument I want to pass say the first two points from the list_points DrawLine( p1 , p2 ). How can I achieve this?

Thanks!

编辑者为: Brock Boland 17 3月, 2014 原因: Paragraph tags added automatically from tizen_format_fix module.

响应

4 回复
Pavel Pertsev
Not sure if I get your question right. Dealing with ArrayListT you have strongly typed collection, so GetAt function returns object of type T. If you declare ArrayListT collection it'll return Point as well. You're probably messing ArrayList with ArrayListT.
kimi
Hi Raju, try explicit casting when u get the object type to Point type and also try using GetItemsN(startIndex,count) method to get the required number of objects at an instant. Kimi.
Alex Dem
Hi, I don't see restrictions to use GetAt() for array list of points: Here first incoming param is index of extracted point and second incoming param is reference to object (object type is Point in our case). GetAt() returns result of execution hence you could use it for checking. see code sample: Point startPoint, endPoint; Tizen::Base::Collection::ArrayListT* list_points = new Tizen::Base::Collection::ArrayListT(); list_points->Add( Point( 20 , 30 ) ); list_points->Add( Point( 10 , 30 ) ); list_points->Add( Point( 40 , 50 ) ); list_points->GetAt(0, startPoint); list_points->GetAt(2, endPoint); AppLog("startPoint x=%d, y=%d ",startPoint.x,startPoint.y); AppLog("endPoint x=%d, y=%d ",endPoint.x,endPoint.y); and after you are able to draw line between 1st and 3rd points via: DrawLine( startPoint, endPoint); I think it is most simple way. But maybe I don't understand some details. Alexey.
Raju Khanal
Thanks!