Hi,
Firstly this has turned out to be quite a long post so please bear with me as its not too difficult but you may need to clarify something with me if i haven't explained it correctly.
So with some help the other day from guys on this forum, i managed to partially set up my 'mapClass' class, but i'm having trouble with it and its not running correctly so i would like some help if possible. I will post the code below so you can see.
What Ive got is a 'Dundrum' class which sets up the listView for an array of items.
Then ive got a 'dundrumSelector' class which I use to set up the setOnClickListener() methods on the listItems and link them to their correct views.
DundrumSelector class..
public static final int BUTTON1 = R.id.anandaAddressButton;
public static final int BUTTON2 = R.id.bramblesCafeAddressButton;
public static final int BUTTON3 = R.id.brannigansAddressButton;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
int position = getIntent().getExtras().getInt("position");
if(position == 0){
setContentView(R.layout.ananda);
};
if(position == 1){
setContentView(R.layout.bramblescafe);
};
if(position == 2){
setContentView(R.layout.brannigans);
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);
}
});
Button bramblesbutton = (Button) findViewById(R.id.bramblesCafeAddressButton);
bramblesbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(),MapClass.class);
myIntent.putExtra("button", BUTTON2);
startActivityForResult(myIntent, 0);
}
});
etc etc....
Then what i did was set up static ints to represent the buttons which you can see at the top of this class, the reason for this is because in my mapClass activity I just want to have one method, because the only thing that is varying is the coordinates to each location.
ie. i dont want to have 100+ map classes essentially doing the same thing other than different coordinates into the method.
So my map class is as follows...
case DundrumSelector.BUTTON1:
handleCoordinates("53.288719","-6.241179");
break;
case DundrumSelector.BUTTON2:
handleCoordinates("53.288719","-6.241179");
break;
case DundrumSelector.BUTTON3:
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();
}
Now this is where my problem is. The onClick() events don't even work from the listView to get into the correct views. I have to comment out the methods in 'DundrumSelector' before I can get into their views.
And this is what I dont understand, firstly why wont the onClick() events work, because its not even on that next view where the map is.
I know this is a very long post and it might be quite confusing so let me know if you want any clarification..
Just to recap, what i'm trying to do is just have one class that sets up the map coordinates, like what i'm trying to do in my 'mapClass'.
Please can someone help or suggest another way of doing this!
Thanks alot everyone for reading this.