Reputation: 131
My app has a basic Google Maps activity, and on the map there is 4 markers which display some text. These markers are displayed on the map using a HashMap.
This is some of the code at the moment -
Double waterPrice = 1.38;
Double foodPrice = 1.23;
mMyMarkersArray.add(new MyMarkers("Tesco", "Tesco", Double.parseDouble("1.1111"), Double.parseDouble("-1.1111"), "Water: €" + waterPrice , "Food: €" + foodPrice , "Address: London"));
mMyMarkersArray.add(new MyMarkers("Sainsburys", "Sainsburys", Double.parseDouble("1.1111"), Double.parseDouble("-1.1111"), "Water: €" +waterPrice , "Food: €" + foodPrice , "Address: Manchester"));
I was wondering, would it be possible to define an array with 5 values such as:
[1.33, 1.23, 1.24, 1.99, 2.01];
And then when the map is loaded first, it takes the value at index 0, assigns it to waterPrice, and then after I click a button or after 5 seconds has passed, it moves on to index 1, index 2 etc and sending this new price to the marker each the time button is clicked. So instead of having my waterPrice
and foodPrice
defined above, I can just iterate through the array, and send the value to the marker.
Could I use two arrays, one for waterPrice and one for foodPrice so that I can assign waterPrice
to index 0 in the array?
Sorry if what I am trying to explain is not really clear, if anyone could help me I would appreciate it. I'm stuck at the moment trying to come up with a way to implement this.
Upvotes: 0
Views: 469
Reputation: 1016
I don't understand very well what you are trying to do, so if my answer is wrong please give more details. If your problem is only with running code after some delay, you could use a Handler
to run code after a specific time. Something like this:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// run after one second
}
}, 1000);
If you have a list with the defined times and prices:
for (int i=0; i<timeList.size(); i++) {
Double time = timeList.get(i);
Double waterPrice = waterPriceList.get(i);
Double foodPrice = foodPriceList.get(i);
handler.postDelayed(new Runnable() {
@Override
public void run() {
// update your marker
}
}, timeInSeconds*1000);
}
Upvotes: 1