Hey there,
Ok so this is what i've got.
Button anandabutton = (Button) findViewById(R.id.anandaAddressButton);
anandabutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(),MapClass.class);
startActivityForResult(myIntent,0);
}
});
This method opens up my MapClass class which at the moment I just have set to show the location of one place.
But I have a load of buttons and rather than making a lot of different mapClass classes for each button, I am wondering can I just use the one class and depending on what button 'id' is pressed, it will check an 'if statement' and then put in the correct coordinates into the method to display the map. It would be a lot neater than coding up like 20-30 classes.
I'm not sure if i've explained that right so if not let me know.
Thanks for any help.
This is my map class now...
public class MapClass extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
int button = getIntent().getExtras().getInt("button", -1);
switch(button){
case DundrumSelector.BUTTON1:
handleCoordinates("53.288719","-6.241179");
break;
case DundrumSelector.BUTTON2:
handleCoordinates("53.288719","-6.241179");
break;
}
}
private void handleCoordinates(String l, String b){
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
String coordinates[] = {l, b};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat*1E6),
(int) (lng*1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
}
and then my other activity is
public static final int BUTTON1 = R.id.anandaAddressButton;
Button anandabutton = (Button) findViewById(R.id.anandaAddressButton);
anandabutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(),MapClass.class);
myIntent.putExtra("button", BUTTON1);
startActivityForResult(myIntent,0);
}
});
For some reason when I try and click on any other item in the list other than BUTTON1 the program crashes. Ive had to take out BUTTON2, BUTTON3 etc because it just keeps crashing if i try and go into their view. but when i comment out this onClick method they all work fine?
Do either of you guys have any openions? Do u understand my problem? Thanks.