I was reading the documentation for polygons and polylines
What is not clear to me is how could I keep a state associated with a polygon?
E.g. if I want to do an action on click that depends on whether the polygon was already clicked on or not how could I know that?
Could I use e.g. tag to add arbitrary info including if the polygon is in click/state?
you can use setTag() with custom object which include click state and other data like
CustomDefinedObject data = new CustomDefinedObject ();// your defined object
data.isClicked=true
data.otherProperty=false
polyline.setTag(data);
and to retrieve info
CustomDefinedObject retrievedData = (CustomDefinedObject)polyline.getTag(data);
Related
I am investigating the use of GraphStream on Android using
api 'com.github.graphstream:gs-ui-android:2.0-alpha'
api 'com.github.graphstream:gs-core:2.0-alpha'
I have managed to construct and display my Graph fine,
However I cannot see how to listen for user interactions on the nodes within my graph.
I need to display a Dialog when any node is clicked on by the user and display the specific nodes information.
I've tried setting a Listener on the org.graphstream.ui.android_viewer.AndroidViewer, however I never received any callbacks
I can drag the displayed nodes around the screen so I know there are default listeners, how to I add my own listeners though?
You can implement ViewerListener with the ViewerPipe like this :
ViewerPipe pipe = fragment.getViewer().newViewerPipe();
pipe.addAttributeSink( graph );
pipe.addViewerListener( this ); // this or any class which implements ViewerListener
pipe.pump();
You can get an exemple here : https://github.com/graphstream/gs-ui-android-test/blob/master/app/src/main/java/ui/graphstream/org/gs_ui_androidtestFull/Activity_TestArrows.java
And here to understand how ViewerPipe works : http://graphstream-project.org/doc/Tutorials/Graph-Visualisation/
I am trying to take advantage of an InfoWindowAdapter to provide custom content for the InfoView. I'm pulling down a JSONArray from my web service and adding the Markers but I'm not seeing how to pass the detail to the call back via a Marker.
#Override
public View getInfoWindow(Marker marker)
In the Javascript API I was able to just set arbitrary marker info. I want to be able to pass info that can be used as conditionals for the custom content, example a marker.status string. So something other than title etc. The view will need a number of custom fields I need to pass in.
perhaps try adding your info or object to the marker as explained here:
http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html
Edit: I also made a post that continues the previous to use the InfoWindowAdapter.
Check it out here!
I am making a calculator same as windows calculator. I am stuck at the history feature. which would be the best UI control to implement the history feature as seen in Windows Calculator?
I also want onclick events on the history.
I'm not sure how you represent a calculation, but you could have a simple class like this:
enum Operator {PLUS,MINUS,DIV,MULT};
class Calculation {
float operand1,operand2;
Operator operator;
public Calculation(float op1,float op2,Operator operator){
this.operand1=op1;
this.operand1=op2;
this.operator=operator;
}
}
Then when a calculation is done, create an object of this type and add it to an ArrayList:
List<Calculation> history = new ArrayList<Calculation>();// history
history.add(new Calculation(5,5,Operator.PLUS));// add a new `Calculation` to our list
Then access the list with history.get(some_integer), based on your UI.
Could you just use a List containing a number of previously entered calculations? If you knew the maximum possible history size in advance, you could just stick with a normal array, but a List will give you more flexibility.
You need to store all the operations and results with an index here. Increase the index every time when you perform an operation.To retrieve the past operation, manipulate the index and you can get the values.You can use Collection API for storing the operations.
I'm wondering a simple way to find back the object corresponding to the clicked item..
They're tons of examples on the web on how to figure out the ListView setup with the setListAdpater, but much less on how to well handle its listener.
Is "by position" the only way ?? I'm wondering a possibility to associate the objects itselves to the adapter, to not have to use their position in list (or even the displayed String!) to find back the Object referred by the clicked label..
Position is what is used always. The ListView works with using the position.
But if you want to access the ListAdapter and get a value out by providing a string, than you will have to extend ListView and implement that functionality yourself. You can overwrite the different methods that handle adding and removing and keep a HashMap where you keep the string representing the object. Then through a getObject(String key) you return the object that is in the hashmap for that key.
How to get the dirty(changed) properties(any controls subclasses of view) amongst a number of properties on a layout. Does android has a dirty flag to mark if the layout has any field that has a changed content??
Actually, i have a layout that has a few edittexts,spinners,datewidgets.Now doing a save should make request to the server only if the user has modified anything .I wanted to know that how can i check if the user has changed anything in that layout or not.Does android has any flag or something that sets itself when the user modifies any input control?
Hmm..Blckberry Does have isDirty(){boolean net.rim.device.api.ui.Manager.isDirty()}method.
The activity is not tightly coupled to the elements in your layout, so you'll have to do this yourself. You could maintain a Map where the key is the id of the layout element, and the value is a boolean that signals if the element has been modified by the user. You would probably need to set up listeners on each element (such as OnKeyListener for your EditTexts) and additionally capture their initial values.
Does android has a dirty flag to mark
if the layout has any field that has a
changed content??
No, sorry.
Bit late with my answer, but the way I do it is to store the form (activity) fields in a container object (for validation, etc). This container object implements the
java.lang.Comparable interface, where T is the same class as the container.
The compareTo(T) method then returns
0 if both objects are equal (thereby form contents haven't changed).
-1 indicates that something has changed and therefore the data is dirty
You can always return other numeric values to indicate what exactly has changed if required.