I need to implement a grid that will show the position of some physical objects. I want to interact with the objects: I want to be able to send commands or request their "health" status (the objects happen to be sensor nodes).
The size of the grid is given by the user but is always square (width=length=a).
Any ideas will be appreciated.
Creation of a custom view might be an option. If so share your thoughts on this.
The grid that I am talking about should look like this
http://1.bp.blogspot.com/_NWSHay-_Gtk/R8hsDLaG9XI/AAAAAAAAAKU/DO6Ltp8v7zY/s1600-h/grid.gif
where my objects are expected to be situated in the nodes of the grid.
Did you try http://developer.android.com/reference/android/widget/GridLayout.html ?
I think you are looking for a GridView.
GridLayout might work too... but it is only supported by API 14 and above.
Related
I have been working on an app that adds views programmatically to a linear layout.
The problem is if I add too many views it will go off the screen.
I would like to know how to check if a certain child has hit the end of the same view group so I could add it into another layout (a linear layout below the first one) before it "flows" and go off the screen. How might I accomplish this?
Rather than reinvent the wheel yourself, I suggest that you check out the FlexboxLayout project by Google: https://github.com/google/flexbox-layout
A FlexboxLayout will automatically give you the behavior you're describing, plus the potential for much more.
Well, there are a good number of ways you could implement this in android other than going through this hustle. What ever you are trying to do at the moment may fall under one of the following cases.
Creating views programmatically most likely means you have a dynamic data set probably from an external source.
Your dataset is limited or static but just more than the average screen can display.
if any of the above apple then you are better off using a ListView or RecyclerView (Recommended). That way your data is full displayed as a scroll-able list and you don't have to worry about some items or views not showing or going of the screen. This can range from simple string list to complex nested views.
This will be very efficient as it will automatically handle optimization and usage of memory as well as performance.
I am writing a browser based application using GWT and making use of websql (yes, I know it is deprecated). I have created a custom table widget (based on FlexTable) and enabled it to scroll with the help of some CSS trickery. What I am striving to achieve (without much success) is that when the user scrolls to the start/end of the current data in the table, an event is fired and the next subset of X rows is returned from the websql DB and replaces the data currently in the table. In order for this to work, I need to keep track of the data offset in the table widget so that I can pass this to the query and use the limit and offset functions of SQL to return the required data. However, I just cannot seem to get the logic right to implement the data offset tracker within the widget. Another complication is that I need the table to be able to scroll 'into the past' (so to speak), so that it can retrieve data from before the initial start point when the table loads.
I have been at this for a number of days now and just cannot seem to get it right. So I was wondering/hoping that someone might be able to point me in the right direction (PLEASE!).
Thanks in advance
Tim
I am not sure why this is causing a problem.
int page = 0;
// when you hit the bottom
page++;
loadData(page);
// when you hit the top
if (page > 0) {
page--;
loadData(page);
}
Tim I think it is not a good idea controlling the scroll with CSS trickery.
I have done something similar soon and controlling all the logic (pagination, scroll positions,...).
What I suggest to use is a gwt's scrollPanel, a HasData widget (like a cellList) your custom AbstractCell (class which is rendered for each row of your list) and asyncDataProvider ( which gives you the onRangeChange handler for asking to your server when the range data display has changed).
You can force/fire that event when in scrollPanel.addScrollHandler detects you are arriving to the end.
If you want to see all of this in action have a look into (click on source code): http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellList
EDIT [according comment below]:
A. If you want to override the data (in the example is X+X+X...) with the new retrieved just maintain always the same range of data displayed [display.setVisibleRange(0, newPageSize);], and start from 0 when you render the new data (on your RangeChange listener).
B. If you need to have control over up and down scrolls instead of taking advantage of the used events internally on the cellList (basically onRangeChange), you can create your custom events and fire them (this option could be easier for your colleagues for understanding everything). And do not worry about controlling up and down scrolls, inside the ShowMorePagerPanel.java you can see a simple example of knowing up and down controls.
Anyway, I did not explain more detailed because I did not see you very convinced to use CellList approach (and I was using my tablet :D ).
If you change your mind, just let me know and I write for you a proper example step by step (this part could be tricky, so if you are lost it is normal ;) ).
I am creating a program containing a map. For the GUI I use CardLayout cus I'm swapping between windows. One of the windows in my program is with a smaller map, and another one is with a bigger map.
When I swap between these two windows I want the information (zoom, waypoints etc.) on the map I just looked at to be transfered to the 2nd map. But I figured that the best way to do this (considering I'm gonna need several thousand waypoints for my use (why is not relevant)) is just to let the same object be at both the cards.
Will this be possible? I will simply adjust the location and the size, but everything else (like zoom and waypoints) will be intact!
-Thanks alot :)
PS: I'm using JXMapViewer
You should separate model and view.
Create a custom model with all the info (zoom, waypoints etc.)
Create two views - panels which keep reference to the same model object and have own params - location and size.
Place in the CardLayout both views and swap when necessary.
I'm developing a system in Java 3D, which consists of a main window where I have an object that I can manipulate (rotate, translate), and I have 3 other smaller windows that show different views from this same object, but can't directly manipulate the object.
The next thing I want to do is to reflect the actions I make in the main window to the other windows, in real time.
Does anyone have any idea of how I can proceed in order to do this?
You should define cameras fo the other windows in a fixed position, and render the object with the same world matrix, but with the different camera's view and projection. Probablyyou already have a code to render the object, you only need to use different cameras for that.
Without any code it is the most precise answer, I believe.
I'm trying to implement a small-scale strategy, taking turns game
implemented in Java, GUI is made with JFace and SWT.
My challenge is to write a GUI implementation of the world map,
where countries will act as clickable buttons. However, countries
have no fixed boundaries, no rectangular shape, and simply no way
I can think of to be described in a grid layout.
This is my first time trying to implement a project of this type,
please advise
If it's a tile based map (like at Civilization) or it's displayed as pixmap, you could save the ownership of each tile/pixel in a two-dimensional array. Just display the map a a simple, clickable pixmap in a canvas an add a MouseListener. If you get a click event at the coordinates (X,Y), you can just get your country like:
Country clickedCountry = myCountriesOnMap[X][Y];
... in your Listener implementing the MouseListener interface. myCountriesOnMap would be of type Country[][].
Of course, you will need an algorithm that will resolve the ownership for each tile/pixel at startup or if a territory gets conquered (I don't know, if this may happen). May be you will have to define your countries as polygons (like you would do it for a HTML map). I cannot help you on this, as I haven't done anything similar jet, but I'm sure you will find something on Google.
Greetings
Sacher
Try to use the OpenStreetMap data. It contains exact country borders and good image export possibilities.
The Key:border tag will show you all borders. You could extract it and calculate your clickable areas.